Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

how to compare a single row with remaining all rows of a matrix?

Asked by Sivakumaran Chandrasekaran on 3 Sep 2012

my input matrix is v=[1 2 3 4 5;3 4 7 8 9;6 4 8 7 9;3 4 7 8 9;3 2 9 8 4]; I am taking second row alone. I have to compare it with all the remaining rows. How to do it. Suggest me simple code which has few lines.

2 Comments

Azzi Abdelmalek on 3 Sep 2012

wha should be you result? a matrix?

Jan Simon on 3 Sep 2012

What have you tried so far? Which problems occurred? What does "compare" exactly mean?

Sivakumaran Chandrasekaran

Products

2 Answers

Answer by Andrei Bobrov on 3 Sep 2012
Edited by Andrei Bobrov on 3 Sep 2012
Accepted answer
out = ismember(v,v(2,:),'rows');

1 Comment

Your reply matches my requirement exactly. Thanks Andrei bobrov.. And I thank all the people who spend their time to answer my query.

Andrei Bobrov
Answer by Azzi Abdelmalek on 3 Sep 2012
Edited by Azzi Abdelmalek on 3 Sep 2012
v=[1 2 3 4 5;3 4 7 8 9;6 4 8 7 9;3 4 7 8 9;3 2 9 8 4]
v2=v(2,:);
comp=any(bsxfun(@minus,v,v2),2))

%the result:

   comp=1     0     1   0    1

that means that fourth row (comp(4)=0) is equal to the second row

0 Comments

Azzi Abdelmalek

Contact us