MATLAB Answers

Adrian
0

Find unique values in a sequence containing at least 3 elements

Asked by Adrian
on 22 Jan 2015
Latest activity Commented on by Adrian
on 22 Jan 2015
I want to find the unique values for each sequence containing minimum 3 repeating elements in a vector. For example, consider the vector:
x = [1 2 2 3 4 4 4 5 6 6 6 6 7 7 7 8];
The output (unique values) should be:
y = [4 6 7];
How can I achieve this?

  0 Comments

Sign in to comment.

1 Answer

Answer by Niels
on 22 Jan 2015
 Accepted Answer

u = unique(x);
a = histc(x,u);
y = u(a>=3);
This should do the trick. First determine the unique values in the vector, then count the number of times they occur. Then consider only the values that occur more than 2 times.

  1 Comment

Thank you very much. It works.

Sign in to comment.