1

I have a vector M with possibilities of multiple duplicates, and I want to create an index vector that ignores all the duplicates. I tried [C,ia,ib] = unique(M) but I don't quite know how to use ia and ib.

Edit: Sorry I missed an important detail, I is an existing index vector, it needs to get rid of all index that contain duplicate value. So the original vector looks like M(I) and I want to 'clean up' up I, if I do directly ia = I it won't preserve the original data of I.

2 Answers 2

2

From http://www.mathworks.co.uk/help/techdoc/ref/unique.html:

[C,ia,ic] = unique(A) also returns index vectors ia and ic, such that C = A(ia) and A = C(ic).

For example:

[C ia ic] = unique([11 22 11 33 22 44])

results in:

C =

   11   22   33   44

ia =

   3   5   4   6

ic =

   1   2   1   3   2   4

Update

In your updated scenario, you should do I = I(ia).

Sign up to request clarification or add additional context in comments.

Comments

0

You can use optional outputs.

a=round(10*rand(1,10)) 

[dummy I]=unique(a,'first'); 

u=a(sort(I));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.