Sort a string array according to equivalent names of another string array

8 次查看(过去 30 天)
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.

采纳的回答

Fangjun Jiang
Fangjun Jiang 2022-11-10
移动:Fangjun Jiang 2022-11-10
names=["A";"B";"C";"D";"E"];
S1=["d";"c";"e";"a";"b"];
[~,index]=ismember(names, upper(S1));
S2=S1(index)
S2 = 5×1 string array
"a" "b" "c" "d" "e"

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by