Copying rows from a matrix that meet a condition into new matrices
Show older comments
I know this is a rookie question, but I am a rookie MATLAB user...
I have the following matrix:
32 734786.452997685 5.70000000000000 361
32 734786.452997685 5.70000000000000 367
1 734786.452997685 5.69500000000000 100
31 734786.453009259 5.69000000000000 175
31 734786.453009259 5.69000000000000 182
what i need to do is put the rows into different matrices according to the value in the first column. so one matrix that only has the '1' rows, one that only has the '31' rows, and one that has only the '32' rows.
this is bloomberg bid/ask/trade data. if anyone knows how to write the bloomberg function that returns the individual bid, ask, and trade data elements i'd gladly take that also.
suggestions?
Accepted Answer
More Answers (2)
Fangjun Jiang
on 4 Nov 2011
Use logical index.
d=[32 734786.452997685 5.70000000000000 361
32 734786.452997685 5.70000000000000 367
1 734786.452997685 5.69500000000000 100
31 734786.453009259 5.69000000000000 175
31 734786.453009259 5.69000000000000 182];
UniCol=unique(d(:,1));
N=numel(UniCol);
Out=cell(N,1);
for k=1:N
index=d(:,1)==UniCol(k);
Out{k}=d(index,:);
end
Timothy Stark
on 4 Nov 2011
0 votes
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!