Sort a string array according to equivalent names of another string array
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Brian
am 10 Nov. 2022
Kommentiert: Brian
am 10 Nov. 2022
I'm trying to sort string array "S1" according to the order of the equivalent string names in the string array "names". New to Matlab so I would tend towards comparing and looping, but hoping there's a more efficient method someone may know using the sort function.

0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 10 Nov. 2022
Verschoben: Fangjun Jiang
am 10 Nov. 2022
names=["A";"B";"C";"D";"E"];
S1=["d";"c";"e";"a";"b"];
[~,index]=ismember(names, upper(S1));
S2=S1(index)
Weitere Antworten (0)
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!