Programming |
Returning Output Arguments
Any variables you place to the left of the equals sign in the function definition line are returned to the caller when the function terminates. If you pass any input variables that the function can modify, you will need to include the same variables as output arguments so that the caller receives the updated value.
For example, if the function readText
shown below reads one line of a file each time is it called, then it must keep track of the offset into the file. But when readText
terminates, its copy of the offset
variable is cleared from memory. To keep the offset value from being lost, readText
must return this value to the caller:
Note If you include output arguments in your function definition line, make sure that your function code assigns a value to each one. |
Passing Optional Arguments to Nested Functions | Function Handles |
© 1994-2005 The MathWorks, Inc.