MATLAB: How to take a layer of a 3d matrix to form a 2d matrix

matrix manipulation

I have a 3d matrix, A, with size, x by y by z. But my application requires me to use this as an array of 2d matrices. So I thought, I could do this…
B = A(:,:,1)% where B is a matrix of size x by y
That doesn't work, is there a way to efficiently do this without several for loops to assign the elements of matrix B one by one

Best Answer

That should work. I do it all the time. If you use any other dimension other than the last, you'll have to wrap the result in squeeze() though.