Export 2 Dimension out of a 3 dimensionoal Array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi
I hava a 3D Array. Now I like to save the content of the 3d array in n 2d arrays
2dArray = zeros(size(3dArray([1],:,:)));
for z = 1: size(3dArray(:)
2dArray(z)=3dArray(z,:,:)
end
What am I doing wrong?
0 Commenti
Risposte (1)
Star Strider
il 8 Nov 2021
I am not certain what is the desired result.
Usually, the intent is to separate the ‘pages’ (third dimension) of the array into separate 2D arrays.
Likely the best option for that is —
Array3D = randi(9, 3, 4, 4);
Array3D(:,:,2) % Display Page (Dleete Later)
A3dsz = size(Array3D)
Arrays2D = mat2cell(Array3D, A3dsz(1), A3dsz(2), ones(1,A3dsz(3)));
Arrays2D{2} % Display Result
Make appropriate changes to get the desired result.
.
9 Commenti
Star Strider
il 8 Nov 2021
The code in Comment overwrites ‘data_2D’ in every loop iteration. Only one (the last) 2D matrix created will result.
My code produces 3 separate matrices as cell arrays.
A small addition to it will squeeze all of them as well —
Array3D = randi(9, 3, 5, 4);
Array3D(2,:,:); % Display Page (Delete Later)
squeeze(Array3D(2,:,:)) % Display Page (Delete Later)
A3dsz = size(Array3D);
Arrays2D = mat2cell(Array3D, ones(1,A3dsz(1)), A3dsz(2), A3dsz(3));
Arrays2D{2}; % Display Result
Arrays2D = cellfun(@squeeze, Arrays2D, 'Unif',0); % Display Result
Arrays2D{2}
.
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!