MATLAB: How to convert a 2d matrix to a 3d matrix

concatenatematrixmultidimensional arraysreshape

A(:,:,1) = ones(2,4);
A(:,:,2) = 2*ones(2,4);
A(:,:,3) = 3*ones(2,4);
C = [ones(2,4);2*ones(2,4);3*ones(2,4)];
In this post and this post, converting 3d matrix A to 2d matrix C is discussed.
However, how do I convert 2d matrix C back to 3d matrix A?
A(:,:,1) =
1 1 1 1
1 1 1 1
A(:,:,2) =
2 2 2 2
2 2 2 2
A(:,:,3) =
3 3 3 3
3 3 3 3
C =
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3

Best Answer

It's time to use reshape function! Please try the following:
A = reshape(C',[2,3,3]);