-1

I have a matrix (220x19) containing numerical dates on the first row and values corresponding for each date. The problem is that the dates aren't sorted. I want to sort the dates, I know that sortrows() functions exist, however, the dates are sorted, will the data follow the corresponding numerical date?

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
Lucas
  • 11
  • 1

1 Answers1

1

Assuming from your description, your Matrix (let's call it A) has the following form:

A = [3,    1,    2;
     0.3,  0.1,  0.2
     0.33, 0.11, 0.22]

where 3, 1 and 2 in the first row correspond to the numerical dates and the other two rows contain the data. Then

B = sortrows(A.')
C = B.'

will give you

C = [1,    2,    3;
     0.1,  0.2,  0.3
     0.11, 0.22, 0.33]

Actually you want to sort column-wise, as I've understood, which is the same as sorting the rows of A transposed.

Brosch
  • 98
  • 8
  • 1
    Recommend using `.'` for the [`transpose()`](https://www.mathworks.com/help/matlab/ref/transpose.html). See also [this answer](https://stackoverflow.com/a/25150319/8239061). – SecretAgentMan Nov 13 '19 at 19:14