# Adding Matching Data from multiple rows

2 ビュー (過去 30 日間)
Maddie Long 2022 年 3 月 18 日

I have a 10x2 table of data and I want to add all the matching names in col 1 data in col 2
A = 10×2 table
Name Num
___________________ ___
Bussiness Name Three 4
I would like the output to be
Name Num
___________________ ___
But I cannot figure out a way to match all the unique names and then add the second column after. I have tried a few different ways without success.
Any help would be appreciated!

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

### 採用された回答

Stephen23 2022 年 3 月 18 日

Name = ["One";"Two";"Three";"One";"Two";"Three";"One";"Two";"Three";"Three"];
Num = [6;3;1;5;22;2;6;3;32;4];
inp = table(Name,Num)
inp = 10×2 table
Name Num _______ ___ "One" 6 "Two" 3 "Three" 1 "One" 5 "Two" 22 "Three" 2 "One" 6 "Two" 3 "Three" 32 "Three" 4
[G,Name] = findgroups(inp.Name);
Num = splitapply(@sum,inp.Num,G);
out = table(Name,Num)
out = 3×2 table
Name Num _______ ___ "One" 17 "Three" 39 "Two" 28
This is one of the approaches shown here:
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Maddie Long 2022 年 3 月 18 日
Thank you so much, I knew it was something simple! You rock

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

### カテゴリ

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

### Community Treasure Hunt

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

Start Hunting!

Translated by