get the value of element from matrix

2 ビュー (過去 30 日間)
ha ha
ha ha 2019 年 5 月 17 日
編集済み: Stephen23 2019 年 5 月 17 日
Let's say: I have matrix A, B
A=[1 1 200; 2 2 2;9 9 9; 5 5 5; 3 3 355];%matrix 5x3
B=[9 9; 1 1; 3 3]%matrix 3x2
How can I call the result matrix somehow the value of two first column in matrix A is the same as in matrix B?
result=[9 9 9; 1 1 200; 3 3 355];

採用された回答

Stephen23
Stephen23 2019 年 5 月 17 日
編集済み: Stephen23 2019 年 5 月 17 日
Simply use ismember and basic MATLAB indexing:
>> [X,Y] = ismember(B,A(:,1:2),'rows');
>> Z = A(Y(X),:)
Z =
9 9 9
1 1 200
3 3 355

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by