I have a time series for which I have a function that returns the local maxima and minima in a matrix that is sorted in descending order by the y coordinate. For example, running it on the following series:
[1 7 3 7 10 12 6 4 6]
would return:
{ {6 , 12}, {2, 7}, {9, 6} }
As the local maxima. How can I sort this matrix so that it is sorted by the index in ascending? I want:
{{2, 7}, {6, 12}, {9, 6}}
EDIT:
I’ve actually modified my function to just return values in index-sorted order. But I would still like to know the best way of doing this (sorting a matrix by one column value).
You want
sortrows(). Note, however, that it works on standard arrays, not the cell arrays that you’ve shown in your question. For example: