Sorting array by datetimes does not work

15 次查看(过去 30 天)
Hi,
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?

回答(1 个)

Mischa Kim
Mischa Kim 2021-1-4
Convert to and sort the table:
T = sortrows(cell2table(HR_date_time_strings),2)
  5 个评论
Mischa Kim
Mischa Kim 2021-1-5
The code runs fine with R2020b. What release are you working with?
Tycho Maas
Tycho Maas 2021-1-7
It works now, somehow my MATLAB decided that after restarting it worked again...
Thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by