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

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

 Accepted Answer

yatoj
yatoj on 19 Nov 2022

0 votes

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

More Answers (0)

Tags

Asked:

on 19 Nov 2022

Answered:

on 19 Nov 2022

Community Treasure Hunt

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

Start Hunting!