How do I locate the most repeated elements in an array/vector?
Mostrar comentarios más antiguos
For example, we have an array
a = [1 1 1 0 1 1 0 2 2 2]
Given an input of this array, how can I find the number(s) in the array that is/are repeated consecutively most often? i.e. return:
[1 2]
New to matlab and not sure how to do this.
Respuestas (2)
Bruno Luong
el 18 de Jul. de 2023
Editada: Bruno Luong
el 18 de Jul. de 2023
a = [1 1 1 0 1 1 0 2 2 2];
i = find([true diff(a)~=0 true]);
n = diff(i);
j = find(n == max(n));
b = a(i(j))
1 comentario
Sebastian
el 23 de Jul. de 2023
Using this FEX download,
[s,~,r]=groupLims(a);
a(s( r==max(r) ) )
ans =
1 2
Categorías
Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!