how to extract 3rd dimensions of cells?
2 views (last 30 days)
Show older comments
Afsaneh
on 3 Jun 2015
Commented: Walter Roberson
on 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.
0 Comments
Accepted Answer
Walter Roberson
on 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 Comments
Walter Roberson
on 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)]);
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!