Filter löschen
Filter löschen

Cell matrix

1 Ansicht (letzte 30 Tage)
Mate 2u
Mate 2u am 9 Feb. 2012
Bearbeitet: Jeremiah am 7 Okt. 2013
Hi there, I have a 37000 x 4 cell array. Columns are like for eg,
'01/02/2012 00:00:01' 'BEST_BID' 4.25000000000000 90
'01/02/2012 00:00:01' 'BEST_ASK' 4.26000000000000 90
'01/02/2012 00:00:01' 'BEST_BID' 4.25000000000000 90
'01/02/2012 00:00:01' 'BEST_ASK' 4.26000000000000 90
'01/02/2012 00:00:16' 'BEST_BID' 4.24000000000000 90
'01/02/2012 00:00:16' 'BEST_ASK' 4.26000000000000 90
'01/02/2012 00:00:17' 'BEST_BID' 4.25000000000000 90
'01/02/2012 00:00:17' 'BEST_ASK' 4.26000000000000 90
Ok now I want to create 2 matrices (separation) one with BEST_BID and one with BEST_ASK. Additionally they both would need to be in order with respect to their times in the first column and maintain the 3rd and 4th column information

Akzeptierte Antwort

the cyclist
the cyclist am 9 Feb. 2012
Here is one of many ways to do it. This is more geared toward maximum readability than maximum efficiency.
[tf,index] = ismember(CA(:,2),{'BEST_BID','BEST_ASK'});
bidArray = CA(index==1,:);
askArray = CA(index==2,:);
bidArray = sortrows(bidArray,1);
askArray = sortrows(askArray,1);
% % I didn't think sortrows worked on cell arrays, but the above seems to work. If not, use this:
% [~,bidTimeOrder] = sort(bidArray(:,1));
% [~,askTimeOrder] = sort(askArray(:,1));
% bidArray = bidArray(bidTimeOrder,:);
% askArray = askArray(askTimeOrder,:);
  1 Kommentar
Mate 2u
Mate 2u am 9 Feb. 2012
Great the top one worked just fine

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Kevin Holst
Kevin Holst am 9 Feb. 2012
For the first part, here's how to create two cell arrays that are BEST_BID and BEST_ASK:
BEST_BID = myArray(strcmp(n(:,2),'BEST_BID'),:);
BEST_ASK = myArray(strcmp(n(:,2),'BEST_ASK'),:);
You said you're wanting to create two matrices, were you actually wanting cell arrays or matrices of the last two columns of the cell?
The sorting thing will take a bit more work to get, I'll have to get back to you on it.
  2 Kommentare
Kevin Holst
Kevin Holst am 9 Feb. 2012
This function from the file exchange might help your sorting problem:
http://www.mathworks.com/matlabcentral/fileexchange/13770-sorting-a-cell-array
Mate 2u
Mate 2u am 9 Feb. 2012
Thank you

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by