
Other Data Structures
end
avg = sum(scores)/(las t - first + 1);
You can run this function using different values for the dynamic field stu den t.
First, initialize the structure that contains scores for a 25-week period:
testscores.Ann_Lane.week(1:25) = ...
[958976827992949289817593...
85 84 83 86 85 90 82 82 84 79 96 88 98];
testscores.William_King.week(1:25) = ...
[878091849987938797878289...
86 82 90 98 75 79 92 84 90 93 84 78 81];
Now run avgscore, supplying the students name fields for the testscores
structure at runtime using dynamic field names:
avgscore(testscores, 'Ann_Lane', 7, 22)
ans =
85.2500
avgscore(testscores, 'William_King', 7, 22)
ans =
87.7500
4-19
Kommentare zu diesen Handbüchern