Sorting array by datetimes does not work
Mostra commenti meno recenti
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?
Risposte (1)
Mischa Kim
il 4 Gen 2021
T = sortrows(cell2table(HR_date_time_strings),2)
5 Commenti
Tycho Maas
il 4 Gen 2021
Modificato: Tycho Maas
il 4 Gen 2021
Mischa Kim
il 4 Gen 2021
Modificato: Mischa Kim
il 4 Gen 2021
Right you are.
DT = datetime({HR_date_time_strings{:,2}}','InputFormat','dd-MM-yyyy HH:mm','Format','preserveinput');
T = sortrows(table({HR_date_time_strings{:,1}}',DT(:)),2)
Tycho Maas
il 5 Gen 2021
Mischa Kim
il 5 Gen 2021
The code runs fine with R2020b. What release are you working with?
Tycho Maas
il 7 Gen 2021
Categorie
Scopri di più su Shifting and Sorting Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!