Create Matrix using loop

1 view (last 30 days)
Sydney Lavan
Sydney Lavan on 7 Apr 2020
Commented: Sydney Lavan on 7 Apr 2020
I have a data file containing 2,239,488 values. I need to arrange these values in a 108*108*192 matrix. The data file is arranged in such matter (0,0,0),(1,0,0),(2,0,0)....(107,0,0),(0,1,0),(2,1,0)...(107,1,0),(0,2,0),(1,2,0).......(107,107,191). i.e. my x coordinates runs fasters (inner loop) and the y in the middle loop and finally z is the outer loop until Ive exhausted the 108*108*192 numbers.
Is there a function or code to take my data file and arrange in such matrix?
Thanks, Sydney

Accepted Answer

David Hill
David Hill on 7 Apr 2020
Look at reshape() function.
reshape(yourMatrix,108,108,192);
  5 Comments
David Hill
David Hill on 7 Apr 2020
A=yourMatrix;
A=A(:);
A=A(A~=0);
B=reshape(A,108,108,192);
Sydney Lavan
Sydney Lavan on 7 Apr 2020
Great this worked !
Thank you, Sydney

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!