Reshaping a complex 3D array into 1D, and back
Afficher commentaires plus anciens
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 commentaires
James Tursa
le 18 Juin 2020
Modifié(e) : James Tursa
le 18 Juin 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
le 18 Juin 2020
Réponse acceptée
Plus de réponses (1)
David Hill
le 18 Juin 2020
1dwave=3dwave(:)';
recovered_wave=reshape(1dwave,size(3dwave));
1 commentaire
Nick Keepfer
le 18 Juin 2020
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!