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?
Asked
Active
Viewed 59 times
-1
-
There are [2 approaches here](https://stackoverflow.com/q/19176189/8239061) that seem relevant if your dates are simply numerical values. – SecretAgentMan Nov 13 '19 at 14:19
-
1Please include a [mcve] in your question – Wolfie Nov 13 '19 at 14:22
1 Answers
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
-
1Recommend 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