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
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
the cyclist 2013 年 4 月 23 日
Guessing this is homework. That's the usual motivator for not wanting to use particular functions.
Matt Kindig
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
Connor 2013 年 4 月 23 日
They are considered repeated because order isn't important here. This is a very small part for my project, and isn't required. My professor said if we could do this we could get some extra credit. Thanks!

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

回答 (1 件)

Matt J
Matt J 2013 年 4 月 23 日
編集済み: Matt J 2013 年 4 月 23 日

0 投票

Hint:
>> sortrows(sort(A,2))
ans =
-6 3 3
2 4 8
2 4 8
You should now find diff() rather helpful.

2 件のコメント

Connor
Connor 2013 年 4 月 23 日
I'm still kind of lost where I go from there. Using diff will give me the difference between each element in each row. So when there are three zeros, I know there is a duplicate row. How do I translate that into eliminating a row? I tried using find, but I'm not too familiar with the find function. Thanks for your help.
Cedric
Cedric 2013 年 4 月 23 日
Lookup ALL and ANY in the doc; you could probably use them at some point, and be aware that ALL, ANY, DIFF, and many others operate along a dimension that you can specify.

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

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2013 年 4 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by