How to combine te same elements in table

I have table like this:
1 1
24 1
52 1
53 4 % element 53 occurs 4 times
53 3 % the same element 53 occurs 3 times
77 1
78 1 % element 78 occurs 1 time
78 5 % the same element 78 occurs 5 times
I have to combine the same elements of first column and count the occurencies from second column - the final table should be:
1 1
24 1
52 1
53 7 %
77 1
78 6 %
Any idea - I'm beginner.
Thanx in advance

2 件のコメント

madhan ravi
madhan ravi 2019 年 1 月 25 日
Which version are you using?
Andrzej Marciniak
Andrzej Marciniak 2019 年 1 月 25 日
Latest

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 25 日

0 投票

[uu,~,gg]=unique(YourArray(:,1));
tt = accumarray(gg, YourArray(:,2));
output = [uu, tt];

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 1 月 25 日

1 投票

Requires 2018a or later:
a=[ 1 1
24 1
52 1
53 4 % element 53 occurs 4 times
53 3 % the same element 53 occurs 3 times
77 1
78 1 % element 78 occurs 1 time
78 5] % the same element 78 occurs 5 times]
T=table;
T.Group=a(:,1);
T.Times=a(:,2);
G=findgroups(T.Group);
T=groupsummary(T,'Group','sum');
T(:,[1 3])

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by