plotting group size vs total member in group of particular size
1 次查看(过去 30 天)
显示 更早的评论
Hi I fairly new to MATLAB and would like to know if there's a way to do this without involving too much looping.
so say I have a array that looks like [1 1 1 2 2 3 4 4 5 ]
I want to know the range of sizes of the groups (there's 3 ones, 2 twos, 1 three, 2 fours, 1 five) i.e I would like to have it return [1 2 3]
And I would also like to know the total number of members in each group size. In this case it would be [2 2 1] since two groups have size 1, two groups have size 2 and one gorup has size 3, etc.
Any help is appreciated!
0 个评论
采纳的回答
dpb
2021-6-16
v =[1 1 1 2 2 3 4 4 5];
% engine
u=unique(v);
ng=histc(v,u);
U=unique(ng)
U =
1 2 3
NU=histc(ng,U)
ans =
2 2 1
histc has been deprecated by TMW in favor ot histcounts, but it doesn't always behave as want it to ... although there's an additional argument to it 'BinMethod','integers' it's just more to remember (I had to go look it up to write this comment) when know precisely how to get what want with the venerable histc
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!