How do I locate the most repeated elements in an array/vector?
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (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))
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!