How do I locate the most repeated elements in an array/vector?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (2)
Bruno Luong
am 18 Jul. 2023
Bearbeitet: Bruno Luong
am 18 Jul. 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))
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!