Arrangement of matrix elements in specific order

조회 수: 1 (최근 30일)
Tanveer ul haq
Tanveer ul haq 2019년 10월 23일
답변: galaxy 2019년 10월 23일
Hello.
I have 2 matrices. A and B.
say:
A = [1 2 4 3];
B = [2 3 1 4];
% the corresponding element (A to B corresponding) of 1 is 2, 2 is 3, 4 is 1 and 3 is 4. Now i need to use this relation in a third matrix C (say).
C = [4 2 3 1];
so that i ger a matrix D having corresponding with C the same as that of A to B. i.e.
D = [1 3 4 2]

채택된 답변

galaxy
galaxy 2019년 10월 23일
A = [1 2 4 3];
B = [2 3 1 4];
C = [4 2 3 1];
for i=1:4
D(find(C == A(i))) = B(i);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by