How to create a limited frequent values in array?

1 回表示 (過去 30 日間)
Zaki
Zaki 2013 年 9 月 27 日
コメント済み: Wayne King 2013 年 9 月 27 日
Is there anyone know how to create limited frequent values in array? Because, what I found is only the most frequent. I'd like to make it like two or three times appear. For example this problem :
Return a list of all values (sorted smallest to largest) that appear exactly three times in the input vector x. So
if
x = [1 2 5 2 2 7 8 3 3 1 3 8 8 8]
then
y = [2 3]

採用された回答

Wayne King
Wayne King 2013 年 9 月 27 日
編集済み: Wayne King 2013 年 9 月 27 日
You can use hist() and unique()
x = [1 2 5 2 2 7 8 3 3 1 3 8 8 8];
[N,bins] = hist(x,unique(x));
bins(N==3)
Of course you can save that output in the vector, y
y = bins(N==3);

その他の回答 (1 件)

Zaki
Zaki 2013 年 9 月 27 日
it's very helpful thank you very much :)
  1 件のコメント
Wayne King
Wayne King 2013 年 9 月 27 日
Can you accept the answer if it answered your question?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by