Replace equal values of two matrices with other values
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Walter Roberson
2019년 11월 21일
[ispresent, idx] = ismember(A, B(:,1));
C = A;
C(ispresent) = B(idx(ispresent), 2);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!