Borrar filtros
Borrar filtros

how to find maximum and second maximum number from vector.

1 visualización (últimos 30 días)
i need to find the maximum and second maximum occurrence of number from vector. . e.g A=[1 2 3 2 2 2 3 3 3 3 3 2 2 45 5 5 5 4 2 2 2 2 2] when i write 'mode(A)'. it only returns one maximum occurrence of number which is '2' in this case. now i have to find the second maximum numbers from same vector. please write its code how to find it? thanx

Respuesta aceptada

Jos (10584)
Jos (10584) el 30 de Mzo. de 2011
One of the easier alternatives:
m1 = mode(x)
xcopy = x ; xcopy(x==m1) = []
m2 = mode(xcopy)
Another options uses unique, histc and sort:
ux = unique(x) ;
n = histc(x,ux) ;
[ns, si] = sort(n,[], 'descend') ;
ux = ux(si) % sort in same order
ux(1:2)

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by