convert a 5 by 10 array into a 2 by 25 cell array in matlab

You can convert a 5 by 10 array into a 2 by 25 cell array in MATLAB using the reshape function and then transposing the result. Here is an example code:

main.m
A = reshape(1:50, 5, 10); % create a 5 by 10 array
B = mat2cell(A, [2 3], repmat(5, 1, 2)); % convert to a 2 by 25 cell array
C = B'; % transpose the result
157 chars
4 lines

In the above code, A is a 5 by 10 array of numbers. The mat2cell function is used to convert A into a 2 by 25 cell array B with the desired grouping of rows and columns. The resulting B is then transposed using the ' operator to get the final 2 by 25 cell array C. Note that the mat2cell function splits A into rows of size 2 and 3 for the first and second row of B, respectively, and columns of size 5 for each of the 2 rows.

gistlibby LogSnag