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

3 views (last 30 days)
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

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 8 Jan 2021
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

Products

Community Treasure Hunt

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

Start Hunting!