MATLAB: I have a matrix [1 1 1 0; 0 1 1 0;1 1 0 1; 0 0 1 1]

row and columns

In this case my matrix is 4 by 4. Is is possible that i can remove last element of fourth row. So that at last i can get 3 by 5 of 5 by 3 matrix?

Best Answer

A = [1 1 1 0; 0 1 1 0;1 1 0 1; 0 0 1 1];
B = reshape(A(1:end-1),3,5);
B
B =
1 0 1 1 0
0 1 0 0 0
1 1 1 1 1
To get it as 5x3 is just changing the call to reshape. You need to make sure you know in which order you want the elements to be reshaped. Remember that MATLAB stores the elements of an array going down the columns.
Related Question