MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
maxLoss = 5×1
104 ×

2.3141
2.3418
0.8767
0.2796
1.6659

Calculate the maximum power loss due to a power outage by cause. To specify that Cause
is the grouping variable, use table indexing. Create a table that contains the maximum
power losses and their causes.

T1 = T(:,'Cause');
[G,powerLosses] = findgroups(T1);
powerLosses.maxLoss = splitapply(@max,T.Loss,G)

powerLosses=10×2 table
Cause maxLoss
________________ _______

attack 582.63
earthquake 258.18
energy emergency 11638
equipment fault 16659
fire 872.96
severe storm 8767.3
thunder storm 23418
unknown 23141
wind 2796
winter storm 2883.7

powerLosses is a table because T1 is a table. You can append the maximum losses as
another table variable.

Calculate the maximum power loss by cause in each region. To specify that Region and
Cause are the grouping variables, use table indexing. Create a table that contains the
maximum power losses and display the first 15 rows.

T1 = T(:,{'Region','Cause'});
[G,powerLosses] = findgroups(T1);
powerLosses.maxLoss = splitapply(@max,T.Loss,G);
powerLosses(1:15,:)

9 Tables

Free download pdf