Using unique-function to add up values

1 回表示 (過去 30 日間)
Lukas Netzer
Lukas Netzer 2021 年 5 月 2 日
回答済み: Matt J 2021 年 5 月 2 日
Hey guys,
I am splitting a column according to it's unique values:
[C, ia, ic] = unique(Location)
Which gives me (examplified):
C/ia/ic:
Location1 1205 8
Location2 9 8
Location3 387 2
Location4 45 2
Location5 653 8
Location6 59 8
Location7 3 1
Location8 1037 1
etc.. numbers may not match..
Now I have another colum containing DiffTime(seconds):
DiffTime:
0
23853
16835
12900
14869
40810
11700
10201
How can I add up DiffTime for each unique Location?
So that i get DiffTimeTotal for Location1, Location2, ...
Thanks for your help!!

採用された回答

Matt J
Matt J 2021 年 5 月 2 日
accumarray(ic, DiffTime)
  1 件のコメント
Lukas Netzer
Lukas Netzer 2021 年 5 月 2 日
Thanks!

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

その他の回答 (1 件)

Matt J
Matt J 2021 年 5 月 2 日
Possibly faster:
totals = splitapply(@sum, DiffTime, findgroups(Location))

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by