MATLAB Answers

0

ignore or delete number or row has been multiply defined?

Asked by Le Xuan Thang on 4 Oct 2019
Latest activity Commented on by Le Xuan Thang on 4 Oct 2019
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

  0 Comments

Sign in to comment.

Products

2 Answers

Answer by Akira Agata
on 4 Oct 2019
 Accepted Answer

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 Comment

Sign in to comment.


Answer by David Hill on 4 Oct 2019

A=unique(A);

  1 Comment

Sign in to comment.