Merge matrix to cell
Show older comments
Hi,
I have a matrix A. A(:,:,1)=[1,1;2,2];A(:,:,2)=[2,2;3,3];A(:,:,3)=[3,3;4,4]
How can I combin these three layers in to one cell layer?
e.g. A(1,1)={1,2,3}; A(1,2)={1,2,3};A(2,1)={2,3,4};A(2,2)={2,3,4}
Thanks!
Answers (1)
Azzi Abdelmalek
on 25 Nov 2013
Edited: Azzi Abdelmalek
on 25 Nov 2013
A(:,:,1)=[1,1;2,2];
A(:,:,2)=[2,2;3,3];
A(:,:,3)=[3,3;4,4];
n=size(A);
[ii,jj]=ind2sub(n(1:2),1:prod(n(1:2)))
out=reshape(arrayfun(@(x,y) squeeze(A(x,y,1:n(3))),ii,jj,'un',0),n(1),n(2));
celldisp(out)
Categories
Find more on Encryption / Cryptography 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!