필터 지우기
필터 지우기

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.
  댓글 수: 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by