how to extract 3rd dimensions of cells?

2 Ansichten (letzte 30 Tage)
Afsaneh
Afsaneh am 3 Jun. 2015
Kommentiert: Walter Roberson am 3 Jun. 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Jun. 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 Kommentare
Afsaneh
Afsaneh am 3 Jun. 2015
Thanks, It really works.
Walter Roberson
Walter Roberson am 3 Jun. 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)]);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices 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!

Translated by