フィルターのクリア

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

15 ビュー (過去 30 日間)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012 年 9 月 3 日
コメント済み: Jacek 2015 年 10 月 25 日
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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 3 日
wha should be you result? a matrix?
Jan
Jan 2012 年 9 月 3 日
What have you tried so far? Which problems occurred? What does "compare" exactly mean?

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 9 月 3 日
編集済み: Andrei Bobrov 2012 年 9 月 3 日
out = ismember(v,v(2,:),'rows');
  1 件のコメント
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012 年 9 月 5 日
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 Center および File ExchangeMATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by