Filter löschen
Filter löschen

I have array of 2500 elements.i would to find a number from this array which is maximum times in array and i don't know that number

1 Ansicht (letzte 30 Tage)
I have array of 2500 elements.i would to find a number from this array which is maximum times in array and i don't know that number

Akzeptierte Antwort

Matthew Eicholtz
Matthew Eicholtz am 5 Nov. 2012
I'm sure there is a one-liner that can solve your problem, but here is one option:
Let
A = randi(10,[2500 1]); % 2500x1 vector with all random integers <= 10
B = unique(A);
[~,j] = max(arrayfun(@(x) sum(A==x),B));
Then the value that appears the most in A is given by B(j).

Weitere Antworten (1)

Jan
Jan am 28 Dez. 2012
This is a job for mode.

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by