MATLAB Answers

get the value of element from matrix

5 views (last 30 days)
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];

  0 Comments

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 17 May 2019
Edited: Stephen Cobeldick on 17 May 2019
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 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags