How to re-order a string array?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
james Green
am 11 Apr. 2022
Kommentiert: Paul
am 11 Apr. 2022
currently the files are orderd like this, the value increasing by 30 each time up to 1830:

however, with the code i've used, matlab orders the files like this:

is there any way i can sort the files to match the original?
dirName = pwd;
files = dir( fullfile(dirName,'*.txt') );
files = {files.name}';
files = sortrows(files,'ascend')
0 Kommentare
Akzeptierte Antwort
Stephen23
am 11 Apr. 2022
Bearbeitet: Stephen23
am 11 Apr. 2022
P = pwd;
S = dir(fullfile(P,'*.txt'));
C = {S.name};
[~,X] = sort(str2double(regexp(C,'\d+','match','once')));
C = C(X);
1 Kommentar
Paul
am 11 Apr. 2022
Or
C = string{S.name});
[~,X] = sort(double(extractBetween(C,"_",".txt")));
C = C(X);
for those of us who can't get our minds around patterns and regexp.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!