How to get the most frequent value of vector on Matlab ?

2 ビュー (過去 30 日間)
Makrim
Makrim 2014 年 4 月 1 日
編集済み: Azzi Abdelmalek 2014 年 4 月 1 日
I have a vector A that contains let say [1,2,2,4]. I am looking for a way to get the most frequent value on A (here 2).

採用された回答

Joseph Cheng
Joseph Cheng 2014 年 4 月 1 日
you can use mode()

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 1 日
編集済み: Azzi Abdelmalek 2014 年 4 月 1 日
A=[1,2,2,4]
b=unique(A);
f=hist(A,b)
[~,idx]=max(f)
out=b(idx)
  1 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 4 月 1 日
why do this when Matlab already has a function to do this like it does for mean and median?

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by