Find unique values in a sequence containing at least 3 elements

4 ビュー (過去 30 日間)
Adrian
Adrian 2015 年 1 月 22 日
コメント済み: Adrian 2015 年 1 月 22 日
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?

採用された回答

Niels
Niels 2015 年 1 月 22 日
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 件のコメント
Adrian
Adrian 2015 年 1 月 22 日
Thank you very much. It works.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by