Data rearrangement inside matrices

1 view (last 30 days)

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 Comments
Vilém Frynta
Vilém Frynta on 1 Apr 2023
I would say it depends on :
  • how are your original data stored
  • how much more data will come (and where).
If you know where the new data will come in your array D, then you can take that into consideration when trying to automate this process. It also depend on how does your array D look like right now, and if there are some 'rules' that (for example, time is always in the first column, etc.) you can follow. If yes, it's quite automat-able.
Alexander Nee
Alexander Nee on 2 Apr 2023
Thank you for your response! I think the final array will contain millions of elements

Sign in to comment.

Accepted Answer

Atsushi Ueno
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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!