Sorting array by datetimes does not work

1 view (last 30 days)
Tycho Maas
Tycho Maas on 4 Jan 2021
Commented: Tycho Maas on 7 Jan 2021
I need to sort my array, notSorted.mat, by datetimes as strings. The code I use for this is the following:
[~, idx] = sort(datenum(notSorted(:,2), 'dd-MM-yyyy HH:mm'), 1, 'ascend');
sorted = notSorted(idx,:);
However, this does not work. Some values are still not correctly sorted. Does anybody know what went wrong?

Answers (1)

Mischa Kim
Mischa Kim on 4 Jan 2021
Convert to and sort the table:
T = sortrows(cell2table(HR_date_time_strings),2)
Tycho Maas
Tycho Maas on 7 Jan 2021
It works now, somehow my MATLAB decided that after restarting it worked again...

Sign in to comment.


Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by