How to create 3D array out of multiple 2D arrays of different dimensions?

1 次查看(过去 30 天)
I have multiple 2D arrays say 34x10, 34x13, 34x15. I want to combine these and create a 3D array of size 34x15x3 where additional elements for 34x10 and 34x13 to reach 34x15 can be zeros.
Thank you in advance

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2021-1-8
Something like this ought to work:
M2Dall = {m1,m2,m3,mN}; % Puting all matrices into one cell-array.
for i3 = numel(M2Dall):-1:1
M3D(1:size(M2Dall{i3},1),1:size(M2Dall{i3},2),i3) = M2Dall{i3};
end
HTH

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by