How do I locate the most repeated elements in an array/vector?
古いコメントを表示
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.
回答 (2 件)
Bruno Luong
2023 年 7 月 18 日
編集済み: Bruno Luong
2023 年 7 月 18 日
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))
Using this FEX download,
[s,~,r]=groupLims(a);
a(s( r==max(r) ) )
ans =
1 2
カテゴリ
ヘルプ センター および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!