MATLAB: How to make a 3D Matrix

matrix array

How to make a 3D Matrix that contains all ones in the first layer, all twos in the second layer and all threes in the third layer?

Best Answer

You can also do it like this, for example for a 2 by 4 by 3
A = ones(2,4,3).*reshape(1:3,1,1,3)