How to replace the 3rd column element of a matrix by comparing 1st and 2nd column of another matrix?

1 回表示 (過去 30 日間)
I have a matrix
A =
1 2 5
1 3 5
1 4 5
1 5 6
2 3 6
2 4 7
3 4 7
3 5 7
4 5 7
and
B=
1 2 3
1 3 4
1 4 5
1 5 6
2 3 4
2 4 5
3 4 5
3 5 6
4 5 6
i want to compare 1st and 2nd column and replace the element of 3rd column of B
for example,
in A when 1st and 2nd column is
[1 2] in 3rd column its corresponding value is 5
so i want to replace B's 3rd column whenever in 1st and 2nd column are 1 2
same way when [1 3] it's value will be updated in B in same format.
please help me...
with regard
Suchismita

採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 6 日
Have a look at ismember(V,B(:,1:2),'row')
  2 件のコメント
suchismita
suchismita 2015 年 5 月 6 日
I was doing this way and was getting error,
[lo,ii] = ismember(B(:,1:2),A(:,1:2)
out = B;
out(lo,3) = A(ii(lo),3)
now i know where was the error...thank u once again

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by