MATLAB: How to extract a n*m from a k*n*m

MATLABmatrix manipulation

I have a large k*n*m matrix and I want to be able to create an n*m for seperate values of k.
So I have tried this:
A = rand(2,3,4)
B(3,4)=0
B = A(2,:,:)
hoping to find a 3*4 matrix equal to the content of A(2,:,:). But this gives me a B(1,3,4) as a result.
Not sure that it should be this complicated?

Best Answer

doc squeeze
A = rand(2,3,4) ;
B = squeeze(A(2,:,:))