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

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).

More Answers (1)

A=[1,2,2,4]
b=unique(A);
f=hist(A,b)
[~,idx]=max(f)
out=b(idx)

1 Comment

why do this when Matlab already has a function to do this like it does for mean and median?

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!