How to select the combinations without repetitions in a matrix?

조회 수: 2 (최근 30일)
Hi Everybody,
I have a question regarding matrix sorting. I have a matrix "A" a 6 by 2 matrix.
A=[
1 2
3 2
1 2
2 1
1 4
2 5];
As you can see row 1,3 and 4 have the same answer but inter changed numbers. How do we get matrix "B" without any combination repeats. Thank you
  댓글 수: 4
Image Analyst
Image Analyst 2014년 2월 1일
Azzi's code should do it then, since you want to take the first occurrence , regardless of the order of the columns. WARNING: If you have floating point numbers and not integers, be aware of the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Adam Silva
Adam Silva 2014년 2월 1일
Hi, I only have integers. But Azzi'z code gave me an error,
??? Error using ==> unique at 33 Unrecognized option.
Error in ==> nodesort at 209 [ii,jj]=unique(sort(A,2),'rows','stable')

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 1일
편집: Azzi Abdelmalek 2014년 2월 1일
[ii,jj]=unique(sort(A,2),'rows','stable')
B=A(jj,:)
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 1일
Then use
[ii,jj]=unique(sort(A,2),'rows')
B=A(jj,:)
Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 1일
Shape commented
Ok got it. I removed the option 'stable'.
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by