reshape array to matrix in matlab

In Matlab, you can use the reshape() function to reshape an array into a matrix. The syntax of the reshape() function is as follows:

main.m
B = reshape(A,m,n)
19 chars
2 lines

where A is the array you want to reshape, m is the number of rows, and n is the number of columns.

Here's an example:

main.m
A = [1 2 3 4 5 6];
B = reshape(A, 2, 3);

% B is now a 2x3 matrix
% B = [1 3 5;
%      2 4 6]
94 chars
7 lines

In this example, the reshape() function takes the array A and reshapes it into a 2x3 matrix B.

related categories

gistlibby LogSnag