# Data rearrangement inside matrices

1 view (last 30 days)
Alexander Nee on 1 Apr 2023
Commented: Alexander Nee on 2 Apr 2023

Hello!
I am working on data preparation for deep learning. Let's say i have A = 0 variable containg time value, B = [0 0; 0.1 0.1; 0.2 0.2] matrix containing X-axis and Y-axis coordinates and C = [10 20 30; 40 50 60; 70 80 90] matrix containing function values. I need to store the data in an array D where the first column will contain time, the second column will contain X-axis values, the third column will contain Y-axis values and the fourth column will contain function values. It can be manually done pretty simple as
D(1:9,1)=A;
D(1:3,2)=B(1);
D(4:6,2)=B(2);
D(7:9,2)=B(3)
D(1:3,3)=B(1:3);
D(4:6,3)=B(1:3);
D(7:9,3)=B(1:3);
D(1:3,4)=C(1,1:3);
D(4:6,4)=C(2,1:3);
D(7:9,4)=C(3,1:3);
However, in reality there will be much more data. Hence, manual filling is inefficient. Is there any function to automize this procedure? Or should i create the for loops?
Thank you,
Alex

##### 2 CommentsShow 1 older commentHide 1 older comment
Alexander Nee on 2 Apr 2023
Thank you for your response! I think the final array will contain millions of elements

Atsushi Ueno on 1 Apr 2023
Moved: Atsushi Ueno on 1 Apr 2023
A = 0; % variable containg time value
B = [0 0; 0.1 0.1; 0.2 0.2]; % matrix containing X-axis and Y-axis coordinates
C = [10 20 30; 40 50 60; 70 80 90]; % matrix containing function values
C = C';
D = [repelem(A,9,1), repelem(B(1:3)',3,1), repmat(B(1:3)',3,1), C(:)]
D = 9×4
0 0 0 10.0000 0 0 0.1000 20.0000 0 0 0.2000 30.0000 0 0.1000 0 40.0000 0 0.1000 0.1000 50.0000 0 0.1000 0.2000 60.0000 0 0.2000 0 70.0000 0 0.2000 0.1000 80.0000 0 0.2000 0.2000 90.0000
Alexander Nee on 2 Apr 2023
Many thanks!