How to sort the cell with string based on dates (earliest date should begin first)
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Geerthy Thambiraj
il 2 Giu 2023
Commentato: Geerthy Thambiraj
il 2 Giu 2023
I want to sort the following cell
{'(Z98.1 Z47.89 Z98.1 Z98.1 10/13/2020), (Z98.1 10/15/2020), (Z98.1 10/9/2020), (Z98.1 11/20/2020)'}
into
{'(Z98.1 10/9/2020), (Z98.1 Z47.89 Z98.1 Z98.1 10/13/2020), (Z98.1 10/15/2020), (Z98.1 11/20/2020)'}
Thank you
4 Commenti
dpb
il 2 Giu 2023
screenshot is useless for anybody to do anything with; my old eyes can't even make it out with the sienna tone overlaying it. We'd have to try to read enough of that to make up something useful to try to do something with; that's just not an effective use of volunteers' time here...
Attach the actual cell array itself (save to a .mat file, then attach it w/ the paperclip)
"Help us help you!"
Risposta accettata
Paul
il 2 Giu 2023
Hi Geerthy,
Here is one approach. Some of the steps can be combined if fewer lines of code are desired.
c = {'(Z98.1 Z47.89 Z98.1 Z98.1 10/13/2020), (Z98.1 10/15/2020), (Z98.1 10/9/2020), (Z98.1 11/20/2020)'};
s = split(c,",")
d = datetime(reverse(extractAfter(extractBefore(reverse(s)," "),1)))
[~,index] = sort(d);
s = s(index);
s = strtrim(s)
s = join(s,", ")
% {'(Z98.1 10/9/2020), (Z98.1 Z47.89 Z98.1 Z98.1 10/13/2020), (Z98.1 10/15/2020), (Z98.1 11/20/2020)'}
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calendar in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!