Reputation: 115
I have a column vector of 3861 x 1 having some numeric values. I want to convert this vector into matrix of dimension 40 x 100 in matlab.The code must fill the first 40 values in one column and then move to next column. Can anyone help me out??
Upvotes: 0
Views: 858
Reputation: 684
You can use the reshape function in matlab to rearrange the elements in a matrix. But you can do so only if the number of elements dont change. So if you have a matrix of 4000x1, you can change it to 40x100 using reshape. So, i guess the ideal way would be to pad your 3861x1 matrix with zeros(or whatever you want to pad it with) to a 4000x1 matrix and then reshape it.
See this:
a = rand(3861, 1);
b = cat(1, a, zeros(139, 1));
c = reshape(b, 40, 100);
Upvotes: 2