Multi Row Tables / Combine information where row is equal?

5 ビュー (過去 30 日間)
Florian Rössing
Florian Rössing 2021 年 12 月 3 日
回答済み: Eric Sofen 2021 年 12 月 3 日
Lets say I run simulations with different parameters A,B and for each of the A and B values i simulate another set of parameters x,y
Parset1=['A';'A';'B';'B'];
Parset2=['x';'y';'x';'y'];
And my simulation maybe produces numbers of false positives from the simulation:
FalsePositives=[3;5;6;9];
table(Parset1,Parset2,FalsePositives)
ans = 4×3 table
Parset1 Parset2 FalsePositives _______ _______ ______________ A x 3 A y 5 B x 6 B y 9
And now maybe i want to get the total number of false positives for all simulations with same Parset1:
CumulativeFalsePositivesbyParset1=[8;8;15;15];
table(Parset1,Parset2,FalsePositives,CumulativeFalsePositivesbyParset1)
ans = 4×4 table
Parset1 Parset2 FalsePositives CumulativeFalsePositivesbyParset1 _______ _______ ______________ _________________________________ A x 3 8 A y 5 8 B x 6 15 B y 9 15
Is there an easy way to do this with code??
Maybe even cleverer, can I make tables like below?
Parset1 | Parset2 | FalsePositives | CumulativeFalsePositives
-------------------------------------------------------------------------------------------------------
| x | 3 |
A --------------------------------------------------- 8
| y | 5 |
-------------------------------------------------------------------------------------------------------
| x | 6 |
B --------------------------------------------------- 15
| y | 9 |
-------------------------------------------------------------------------------------------------------

採用された回答

Eric Sofen
Eric Sofen 2021 年 12 月 3 日
You can use varfun to apply the cumsum function to each group defined by Parset1.
Parset1=['A';'A';'B';'B'];
Parset2=['x';'y';'x';'y'];
FalsePositives=[3;5;6;9];
t = table(Parset1,Parset2,FalsePositives);
tc = varfun(@cumsum,t,"GroupingVariables","Parset1","InputVariables","FalsePositives")
% all in one table - copy over the original FalsePositives data
tc.FalsePositives = t.FalsePositives

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by