Loop through a table using a specific condition and generate new table satisfying the particular condition
Show older comments
Example table
ID Value
ID1 5
ID1 7
ID2 3
ID1 1
Condition: If IDs are the same add the corresponding values and generate new table. The new table should be:
ID Value
ID1 12
ID2 3
ID3 1
Accepted Answer
More Answers (2)
ID = ["ID1";"ID1";"ID2";"ID3"];
Value = [5;7;3;1];
T = table(ID,Value)
G = groupsummary(T,'ID','sum')
Lei Hou
on 9 Sep 2024
0 votes
rowfilter is used to select table rows meeting specific condition. It might be helpful to you, too.
https://www.mathworks.com/help/matlab/ref/matlab.io.rowfilter.html#mw_3c39fb64-020a-4cba-9343-7667662df166
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!