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

15 次查看(过去 30 天)
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.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-9-3
编辑:Andrei Bobrov 2012-9-3
out = ismember(v,v(2,:),'rows');
  1 个评论
Sivakumaran Chandrasekaran
Your reply matches my requirement exactly. Thanks Andrei bobrov.. And I thank all the people who spend their time to answer my query.

请先登录,再进行评论。

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-9-3
编辑:Azzi Abdelmalek 2012-9-3
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
  1 个评论
Jacek
Jacek 2015-10-25
For the future generations: I tested both solutions and solution proposed by Azzi is much faster, exactly 9x faster in my application, what was very important for me (large-scale data structures reorganization).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by