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

2 Ansichten (letzte 30 Tage)
Makrim
Makrim am 1 Apr. 2014
Bearbeitet: Azzi Abdelmalek am 1 Apr. 2014
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).

Akzeptierte Antwort

Joseph Cheng
Joseph Cheng am 1 Apr. 2014
you can use mode()

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 1 Apr. 2014
Bearbeitet: Azzi Abdelmalek am 1 Apr. 2014
A=[1,2,2,4]
b=unique(A);
f=hist(A,b)
[~,idx]=max(f)
out=b(idx)
  1 Kommentar
Joseph Cheng
Joseph Cheng am 1 Apr. 2014
why do this when Matlab already has a function to do this like it does for mean and median?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by