Convert vector of decimals to matrix order by integer steps
Show older comments
Hello all, my first post and first loop.
Want I would like to achieve is to rearrange a record of data composed out of decimal numbers, e.g. V=[1.1 1.3 1.5 1.6 1.9 2 2.1 2.5..3.2 3.6..4] to a matrix in which its columns are represented by each integer step. M=[1.1 1.3 1.5 1.6 1.9;2 2.1 2.5...;3 3.2 3.6...;4]'
Now I thought of doing this with a loop the following way
V=Drafts96(:,1);
j=1
for i=1:length(V);
if V(i,1)<ceil(V(i,1));
M(i,j)=t4(i);
else V(i,1)>=ceil(V(i));
j=j+1;
M(i,j)=V(i);
end
end
My thoughts behind this are, go through each value and check if it is less than the ceil of the number, if so assign it row i from the column j. If not, assign a new column (j+1) in the matrix to it.
Needless to say that this isn't working out. Could you please help me! If you can add the improved code even better. Thanks
3 Comments
Matt Kindig
on 8 Nov 2012
Edited: Matt Kindig
on 8 Nov 2012
Are you guaranteed to have the same number of decimal numbers for each integer step? That is, you have 5 numbers that are between 1 and 2-- is this the same for all integer steps? If not, then you won't be able to construct a matrix properly, as the number of columns per row will differ. If so, why not just do a reshape() of V?
ZyMag
on 8 Nov 2012
Walter Roberson
on 8 Nov 2012
See my Answer.
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!