Combine 2D matrices to form 3D one in Matlab

巧了我就是萌 提交于 2019-12-01 20:34:39

Using cat to concatenate along the third dimension might be the elegant way -

D = cat(3,A,B,C)

Here, the first input argument 3 specifies the dimension along which the concatenation is to be performed.

Like this?

A = 1*ones(20,2);
B = 2*ones(20,2);
C = 3*ones(20,2);

D = zeros(20,2,3);  % Preallocate the D Matrix
D(:,:,1) = A;       
D(:,:,2) = B;
D(:,:,3) = C;

D(1,1,1)  % prints 1
D(1,1,2)  % prints 2
D(1,1,3)  % prints 3
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!