how to extract 3rd dimensions of cells?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Afsaneh
le 3 Juin 2015
Commenté : Walter Roberson
le 3 Juin 2015
i have a cell array which in every cell i have a 3 dimensional matrix.(x,y,3)
now i want to extract 3rd dimension of all cells: (:,:,1)
how can i do that without using for loop?
thanks.
0 commentaires
Réponse acceptée
Walter Roberson
le 3 Juin 2015
ResultCell = cellfun(@(M) M(:,:,1), YourCellArray, 'Uniform', 0);
You might possibly want to
cat(3, ResultCell{:})
if you want the result as a 3D matrix stacking the individual layers, provided the individual layers are all the same size.
2 commentaires
Walter Roberson
le 3 Juin 2015
In the case where all of the arrays have the same size, and you want the result as a stacked matrix, there is also
T = cat(4, YourCellArray{:});
Result = reshape(T(:,:,1,:), [size(T,1), size(T,2), size(T,4)]);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!