substitute values from one matrix to another

Suppose I have a matrix
A = [1 2;1 2;2 4;2 4];
and
B= [1 0.1;2 0.2];
I want to have a matrix 3 * 2 matrix C where *the first column of C is the first column of A *for each row, the value of the second column of C is the value of the second column of B that corresponds to the value of the first column of C.
Thus the output is
C = [1 0.1;1 0.1;2 0.2;2 0.2];
Please advise.

 채택된 답변

Akira Agata
Akira Agata 2018년 4월 2일

0 개 추천

How about using ismember function, like:
[~,loc] = ismember(A(:,1),B(:,1));
C = [A(:,1),B(loc,2)];

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2018년 4월 2일

답변:

2018년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by