Asked by Gimpy
on 26 May 2013

Hi, I have the following matrix:

data=[10 1 2 3; 11 4 5 6; 12 7 8 9; 17 4 5 6]

I want to do a query with the following matirx:

built a matrix base on the element value 10 and 17

lookfor=[10;17]

And I'm looking for the following result(values associate with 10 and 17 in this case)

anwser=[10 1 2 3; 17 4 5 6]

I'm looking for a dynamic anwser, data matrix and lookfor matrix will vary and be much more bigger.

thank you in advance for your precious anwsers.

*No products are associated with this question.*

Answer by Azzi Abdelmalek
on 26 May 2013

Edited by Azzi Abdelmalek
on 26 May 2013

Accepted answer

out=[data(any(data==17,2),:);data(any(data==10,2),:)]

%or

out=data(any(ismember(data,lookfor),2),:)

Show 1 older comment

the cyclist
on 27 May 2013

Answer by the cyclist
on 26 May 2013

Edited by the cyclist
on 26 May 2013

rowIndex = ismember(data(:,1),lookfor); answer = data(rowIndex,:);

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments