MATLAB: How to convert a 3D matrix into 2D matrix

MATLABmatrix

Hi,
I am trying to convert 3000x64x278 into 3000*64 rows and 278 columns.
I do know that it can be done something like this:
for example A is of 3000x64x278 matrix so I can call its first matrix as
B=A(:,:,1);
to change it into 3000*64 that means every column under one column I can do
B=B(:);
so There are more 277 columns to fill, how should I do that?
Thanks.

Best Answer

Use reshape.
>> A = reshape(1:4*3*2,4,3,2) % array of size (4,3,2)
A(:,:,1) =
1 5 9
2 6 10
3 7 11
4 8 12
A(:,:,2) =
13 17 21
14 18 22
15 19 23
16 20 24
>> S = size(A);
>> M = reshape(A,[S(1)*S(2),S(3)]) % matrix of size (4*3,2)
M =
1 13
2 14
3 15
4 16
5 17
6 18
7 19
8 20
9 21
10 22
11 23
12 24