reshape matrix size [25x2] to [1x1x15] in matlab

You can reshape a matrix of size [25x2] to [1x1x15] in Matlab by following the code below:

main.m
% create a matrix of size 25x2
A = rand(25,2);

% reshape the matrix to size 1x1x15
B = reshape(A',[1,1,15]);
110 chars
6 lines

Explanation:

  • The function reshape takes the original matrix A as its first input.
  • The ' operator is used to transpose A so that we get a row vector of length 50.
  • We then specify the desired dimensions of the final output as the second input to reshape.
  • We use 1x1x15 to get a 3D array of dimensions 1 x 1 x 15, which is equivalent to a matrix of size [1x15] where each element is a row vector of length 2.

Note that the ' operator is used to ensure that the original matrix A is reshaped column-wise.

gistlibby LogSnag