Sorting cell arrays with characters and numbers
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Araya Mengistu
am 30 Okt. 2022
Kommentiert: Thomas Jarry
am 5 Nov. 2022
Given a cell array such as {'a1', 'a2', 'a3'...'a9', 'a10', 'a11','a12'}, in random order ofcourse, using the sort function gives me {'a1', 'a10', 'a11','a12','a1','a2',...'a9'}. What method can be used to get the right order?
0 Kommentare
Akzeptierte Antwort
Stephen23
am 30 Okt. 2022
Bearbeitet: Stephen23
am 30 Okt. 2022
"What method can be used to get the right order?"
You could download my FEX submission NATSORT:
unzip it onto your MATLAB search path or into the current directory, then call it like this:
C = {'a11', 'a9', 'a3', 'a2', 'a12', 'a1','a10'}
D = natsort(C)
2 Kommentare
Weitere Antworten (1)
Walter Roberson
am 30 Okt. 2022
Bearbeitet: Walter Roberson
am 30 Okt. 2022
MATLAB already gives the "right" order, just not the order you want.
https://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sort
0 Kommentare
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!