i want to get string array corresponding another num array

2 Ansichten (letzte 30 Tage)
민성
민성 am 28 Nov. 2022
Kommentiert: Stephen23 am 28 Nov. 2022
A = [ "a", "b", "c"]
B = [ 4, 5, 6]
if B change to [ 6, 4, 5 ]
i want to output A= ["c", "a", "b"]

Akzeptierte Antwort

Stephen23
Stephen23 am 28 Nov. 2022
Aold = ["a","b","c"];
Bold = [4,5,6];
Bnew = [6,4,5];
[X,Y] = ismember(Bnew,Bold);
Anew = Aold(Y(X))
Anew = 1×3 string array
"c" "a" "b"
  2 Kommentare
민성
민성 am 28 Nov. 2022
thank you
but i want use same var name A , B not use Bnew Bold
how to?
Stephen23
Stephen23 am 28 Nov. 2022
"but i want use same var name A , B not use Bnew Bold"
A = ["a","b","c"];
B = [4,5,6];
tmp = B;
B = [6,4,5];
[X,Y] = ismember(B,tmp);
A = A(Y(X))
A = 1×3 string array
"c" "a" "b"

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by