MATLAB: Help with Reshaping Multidimensional Arrays

columnwiseindexingMATLABmultidimensional arraysreshape

I have Multidimensional Arrays, but I need of a reshaped matrix, indexing columns of each "dimension".
The number of arrays and number of rows can change according to the user, like that:
A (1:x, 1:3, 1:y) if x= 3 and y = 2
A(:,:,1)= [1 2 3
4 5 6
7 8 9];
A(:,:,2)= [10 11 12
13 13 15
16 17 18];
Matlab answer
B = Reshape (A,x*y,3)
B= [1 3 11
4 6 13
7 9 17
2 10 12
5 13 15
8 16 18];
I need the answer:
B= [1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18];
Thank for your help

Best Answer

reshape(permute(A,[1,3,2]),x*y,3)