フィルターのクリア

plotting group size vs total member in group of particular size

2 ビュー (過去 30 日間)
Maggie liu
Maggie liu 2021 年 6 月 16 日
コメント済み: Maggie liu 2021 年 6 月 16 日
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!

採用された回答

dpb
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 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by