ignore or delete number or row has been multiply defined?

1 回表示 (過去 30 日間)
Le Xuan Thang
Le Xuan Thang 2019 年 10 月 4 日
コメント済み: Le Xuan Thang 2019 年 10 月 4 日
hell everyone!
I have an example:
if i have an array like this: [1 2 3 4 5 6 7 8 9 10 ...
1 2 11 12 13 14 ]
you can see that number: 1 and 2 is multiply defined: is twice.
How can i delete row has been multiply defined: like you just 1 time defined the number if 2 time defined that number then delete that number or entire rows of that number from matrix?
Results is: [1 2 3 4 5 6 7 8 9 10 11 12 13 14];
Tks.
LXT

採用された回答

Akira Agata
Akira Agata 2019 年 10 月 4 日
Simple solution will be:
result = unique(yourArray);
If you want to keep element's order, please try the following:
[~, ia] = unique(yourArray);
result = yourArray(sort(ia));

その他の回答 (1 件)

David Hill
David Hill 2019 年 10 月 4 日
A=unique(A);

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by