grouping elements of a matix according to an increasing order of dates

Asked by antonet on 24 May 2012
Latest activity Commented on by antonet on 24 May 2012

Hi all,

i have a matrix A which I have sorted according to the command zoi=sortrows(A, 3 ) and the result is zoi=

         'PDL12'    '01-01-2011'    [     -0.0138]
         'PDL13'    '01-01-2011'    [      0.3529]
         'PDL12'    '01-11-2009'    [     -0.0812]
         'PDL13'    '01-11-2009'    [     -0.2377]
             'PDL12'    '04-10-2009'    [     -0.0208]

And I would like to have

             'PDL12'    '04-10-2009'    [     -0.0208]
         'PDL12'    '01-11-2009'    [     -0.0812]
         'PDL13'    '01-11-2009'    [     -0.2377]
        'PDL12'    '01-11-2009'    [     -0.0812]
         'PDL13'    '01-01-2011'    [      0.3529]

In other words, i want to group all the elements that correspond to the earliest date, then all the elements that correspond to the date after the earliest one and so forth. Any suggestions?

thanks

0 Comments

antonet

Tags

Products

No products are associated with this question.

1 Answer

Answer by Thomas on 24 May 2012
Accepted answer
a={         'PDL12'    '01-01-2011'    [     -0.0138]
'PDL13'    '01-01-2011'    [      0.3529]
'PDL12'    '01-11-2009'    [     -0.0812]
'PDL13'    '01-11-2009'    [     -0.2377]
'PDL12'    '04-10-2009'    [     -0.0208]}
d=datenum(a(:,2),'dd-mm-yyyy');
[l,idx]=sortrows(d);
a(idx,:)                     % output

1 Comment

antonet on 24 May 2012

Excellent!

Thomas

Contact us