create a new array with group sum
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Igenyar
am 28 Jul. 2023
Kommentiert: Igenyar
am 28 Jul. 2023
I have the following data.
1690492071 238581 1.3
1690492071 238582 1.0
1690492071 238580 0.3
1690492071 238576 0.0
1690492071 238577 0.0
1690492071 238579 0.0
1690492071 238583 0.0
1690492071 238584 0.0
1690492071 238585 0.0
1690492071 238586 0.0
1690492076 238581 1.7
1690492076 238582 1.3
1690492076 238576 0.0
1690492076 238577 0.0
1690492076 238579 0.0
1690492076 238580 0.0
1690492076 238583 0.0
1690492076 238584 0.0
1690492076 238585 0.0
1690492076 238586 0.0
...
The first column is the group id and the third column is the value I want to sum for each group. The result should be:
1690492071 2.6
1690492076 3.0
...
I have been struggling for hours, really appreciate help given.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 28 Jul. 2023
data = [ ...
1690492071 238581 1.3
1690492071 238582 1.0
1690492071 238580 0.3
1690492071 238576 0.0
1690492071 238577 0.0
1690492071 238579 0.0
1690492071 238583 0.0
1690492071 238584 0.0
1690492071 238585 0.0
1690492071 238586 0.0
1690492076 238581 1.7
1690492076 238582 1.3
1690492076 238576 0.0
1690492076 238577 0.0
1690492076 238579 0.0
1690492076 238580 0.0
1690492076 238583 0.0
1690492076 238584 0.0
1690492076 238585 0.0
1690492076 238586 0.0];
[totals, groups] = groupsummary(data(:,3), data(:,1), "sum");
format long g
results = [groups, totals]
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!