如何统计一个数组中的元素序列分布?。

比如一串111111122111121111331111333的向量,我想统计它里面1,2,3的序列结构,比如:
1:1111111有1个,1111有3个;
2:22有1个,2有1个;
3:33有2个。
现有一串2000位的由1,2,3组成的数组,有什么函数可以实现呢?

 采纳的回答

yatoj
yatoj 2022-11-19

0 个投票

x = '111111122111121111331111333';
a = mat2cell(x,1,diff([0 find(diff(x)) numel(x)]));
[au,~,iau] = unique(a);
au
accumarray(iau,1)
此回复为最佳答案回复此楼

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!