Change matrix dimensions from 4D to 2 D : matrix manipulation
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Amine Ben Ayara
am 12 Dez. 2016
Beantwortet: Kenny Kim
am 13 Dez. 2016
Dear Matlab community, I am still trying to manipulate some of my output here by converting 4D matrices to 2D. I am having a hard time using "squeeze" and "reshape". I have this matrix (5by5 by 14680 by 30)[ this is basically 30 sets of 14680 of 5by5 matrices), and I need to extract only all the 1st columns from each 5by5 matrices, to have 14680 of (5*1) arrays/matrices, then transpose the (5*1)' so my final matrix has the following dimensions : Final (14680by5) two dimensions only with each row(:,1:5) has the elements from the extracted (5*1) arrays from the step before. I would really appreciate any help! thank you matlab community! Amine
3 Kommentare
Matt J
am 12 Dez. 2016
It would also be good to mention in what way this post is not redundant with respect to
Akzeptierte Antwort
Walter Roberson
am 12 Dez. 2016
Output = squeeze( mat2cell( permute(YourMatrix,[3 1 2 4]), size(YourMatrix,3), size(YourMatrix,1), ones(1,size(YourMatrix,2)), ones(1,size(YourMatrix,4)) ) );
Output will now be a 5 x 30 cell array in which each element is a 14680 x 5 array formed by extracting first columns and making them rows.
2 Kommentare
Walter Roberson
am 13 Dez. 2016
Output = reshape( permute( YourMatrix(:,1,:,), [3 1 4 2]), size(YourMatrix,3), []);
Weitere Antworten (1)
Kenny Kim
am 13 Dez. 2016
This should make the matrix you were looking for:
datatemp = permute(squeeze(data(:,1,:,:)),[2 1 3]);
datatemp = reshape(datatemp,[size(datatemp,1),size(datatemp,2)*size(datatemp,3)]);
where data is the variable name for your 4D matrix.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!