Matlab help error?
- From: dvt <dvt+usenet@xxxxxxx>
- Date: Thu, 31 Jan 2008 15:13:44 -0500
I found the following in Matlab R2007b help. A function (avgscore) is defined with three inputs (student, first, last). Later in the example, the function is called with four inputs. Is this an error in the help text or am I missing something?
---- copied text follows ----
Dynamic Field Names Example
The avgscore function shown below computes an average
test score, retrieving information from the testscores structure
using dynamic field names:
function avg = avgscore(student, first, last)
for k = first:last
scores(k) = testscores.(student).week(k);
end
avg = sum(scores)/(last - first + 1);
You can run this function using different values for the dynamic field student. First, initialize the structure that contains scores for a 25 week period:
testscores.Ann_Lane.week(1:25) = ...
[95 89 76 82 79 92 94 92 89 81 75 93 ...
85 84 83 86 85 90 82 82 84 79 96 88 98];
testscores.William_King.week(1:25) = ...
[87 80 91 84 99 87 93 87 97 87 82 89 ...
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
---- end copied text ----
--
Dave
dvt at psu dot edu
.
- Follow-Ups:
- Re: Matlab help error?
- From: Walter Roberson
- Re: Matlab help error?
- Prev by Date: Re: Simple(?!) GUI Editbox question.
- Next by Date: Re: Simple(?!) GUI Editbox question.
- Previous by thread: Simple(?!) GUI Editbox question.
- Next by thread: Re: Matlab help error?
- Index(es):