フィルターのクリア

How can I get "least frequent" number from a vector?

5 ビュー (過去 30 日間)
Sandy
Sandy 2014 年 6 月 26 日
I know that "mode" is used to get the most frequent number in a vector. Is there any function that returns the "least frequent" number?
For example, a vector: 1 1 2 2 3 3 4 5 5 5 returns 4 since this number only appears once and all others appear more than once.
I guess I can solve this problem use "unique" and "hist", but I am just wondering if there is any better solution than that.
Thank you very much.

採用された回答

Jos (10584)
Jos (10584) 2014 年 6 月 26 日
Option 1: You can copy the code from mode.m and replace the function max by the function min on line 130 (in R2014a). Edit the help text accordingly, and save.
Option 2.
V = [2 2 1 1 4 5 5 5]
uv = unique(V)
n = histc(V,uv)
[m,i] = min(n)
minmode = uv(i)
  2 件のコメント
Sandy
Sandy 2014 年 6 月 30 日
Thank you, I love the first option.
Simão Pedro da Graça Oliveira Marto
In Option 1, in Matlab 2018b, you need to replace the max with a min in line 163, but also replace the "zeros" with "inf" in line 161.

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

その他の回答 (0 件)

カテゴリ

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