How to delete repeated rows without using unique function?
이전 댓글 표시
I am looking for a way to delete repeated rows without using the unique function. For example if I have the matrix
A=[2 4 8; 8 2 4; 3 3 -6]
one of the first two rows needs to be deleted. Order doesn't need to be kept. I'm sure I need to use sort, and maybe find or diff. I'm not exactly sure how to go about it.
Any and all help is appreciated!
댓글 수: 4
Kye Taylor
2013년 4월 23일
Why don't you want to use the unique function? It's second output is gonna be real helpful.
the cyclist
2013년 4월 23일
Guessing this is homework. That's the usual motivator for not wanting to use particular functions.
Matt Kindig
2013년 4월 23일
It's strange that you consider the first two rows of A to be "repeated", since the order of the elements is different (one is a permutation of the other). Is this what you want?
Connor
2013년 4월 23일
답변 (1개)
Hint:
>> sortrows(sort(A,2))
ans =
-6 3 3
2 4 8
2 4 8
You should now find diff() rather helpful.
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!