Replace equal values of two matrices with other values

조회 수: 1 (최근 30일)
Daniel Rohrer
Daniel Rohrer 2019년 11월 21일
답변: Walter Roberson 2019년 11월 21일
Hi,
I got following example matrices:
A = [0 8 29; 131 15 98; 25 827 9; 150 88 826];
B = [131 0; 827 1; 826 3];
I'd like to achieve following result:
C = [0 8 29; 0 15 98; 25 1 9; 150 88 3];
So I would like to replace the equal values of A and the first column of B with the values of the second column of B
My guess is ismember but I couldn't figure out a working solution

채택된 답변

Walter Roberson
Walter Roberson 2019년 11월 21일
[ispresent, idx] = ismember(A, B(:,1));
C = A;
C(ispresent) = B(idx(ispresent), 2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by