Reshaping a complex 3D array into 1D, and back
Show older comments
I have a 3D complex array of size (nx,ny,nz).
For post-processing purposes I need to convert into a flattened array of size (1,nx*ny*nz)
I then need to convert it back into its 3D form.
The issue here is that the following code destroys the original formatting of the 3D array
1dwave = reshape(3dwave,[nx*ny*nz,1]);
recovered_wave = reshape(1dwave,size(3dwave));
In essence:
1dwave != recovered_wave
Can somebody tell me what the correct way to do this is?
i.e. How can I convert from 3D -> 1D -> 3D whilst preserving shape of the original 3D array
2 Comments
James Tursa
on 18 Jun 2020
Edited: James Tursa
on 18 Jun 2020
The reshape( ) function does not change the memory order of the elements. What you have should have worked. Can you give a small example where it doesn't work? Are you sure the original size is strictly 3D with dimensions nx x ny x nz?
Nick Keepfer
on 18 Jun 2020
Accepted Answer
More Answers (1)
David Hill
on 18 Jun 2020
1dwave=3dwave(:)';
recovered_wave=reshape(1dwave,size(3dwave));
1 Comment
Nick Keepfer
on 18 Jun 2020
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!