Your matrix is 5x50. You need to understand how the elements lie in sequence in memory. MATLAB stores each column in sequence. So all of column 1, then all of column 2, etc.
That means all of the first 25 elements of your matrix are stored one after another. If your matrix is called X, then just do this:
This will stuff all 25 of the x1 elements into the first column of the reshaped matrix.
As a smaller example, consider what happens to the vector 1:50, when I do this reshape:
reshape(1:50,5,10)
ans =
1 6 11 16 21 26 31 36 41 46
2 7 12 17 22 27 32 37 42 47
3 8 13 18 23 28 33 38 43 48
4 9 14 19 24 29 34 39 44 49
5 10 15 20 25 30 35 40 45 50
So I started with a vector 1:50. Then turned it into a 5x10 matrix. Where did those elements go? As you can see, MATLAB stores them going down each column, one after another. A reshape does not change the sequence of where elements are stored, only how the shape of the matrix is interpreted.
Learning how MATLAB stores the elements of a matrix in memory is one of the most important things you can do to really start to understand MATLAB.
Best Answer