Programming Previous page   Next Page

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:


Previous page  Passing Optional Arguments to Nested Functions Function Handles Next page

© 1994-2005 The MathWorks, Inc.