i want to get string array corresponding another num array

조회 수: 2 (최근 30일)
민성
민성 2022년 11월 28일
댓글: Stephen23 2022년 11월 28일
A = [ "a", "b", "c"]
B = [ 4, 5, 6]
if B change to [ 6, 4, 5 ]
i want to output A= ["c", "a", "b"]

채택된 답변

Stephen23
Stephen23 2022년 11월 28일
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
민성
민성 2022년 11월 28일
thank you
but i want use same var name A , B not use Bnew Bold
how to?
Stephen23
Stephen23 2022년 11월 28일
"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"

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by