Grouping the data of two variables by sum

1 次查看(过去 30 天)
I have a data with 3 columns R, Z, E. E is a function of R and Z. I would like to add the E coulmn for the same value of R and Z. For example, from the data below, I want to add all the E values for R=1 and Z= 3. Can I get some suggestion?
R Z E
1 3 0.5
3 2 0.4
4 1 0.3
1 3 0.1
1 2 0.5
3 2 0.4

采纳的回答

the cyclist
the cyclist 2023-11-11
R = [1; 3; 4; 1; 1; 3];
Z = [3; 2; 1; 3; 2; 2];
E = [0.5; 0.4; 0.3; 0.1; 0.5; 0.4];
tbl = table(R,Z,E)
tbl = 6×3 table
R Z E _ _ ___ 1 3 0.5 3 2 0.4 4 1 0.3 1 3 0.1 1 2 0.5 3 2 0.4
groupsummary(tbl,["R","Z"],"sum","E")
ans = 4×4 table
R Z GroupCount sum_E _ _ __________ _____ 1 2 1 0.5 1 3 2 0.6 3 2 2 0.8 4 1 1 0.3

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by