In MATLAB, function arguments are evaluated when the function is called. MATLAB provides two methods for passing arguments to functions: positional arguments and named arguments.
Positional arguments are passed in the order in which they are listed in the function definition. For example, consider the following function definition:
main.m49 chars4 lines
You can call this function with positional arguments as follows:
main.m34 chars4 lines
Named arguments can be passed to a function in any order by specifying the argument name followed by its value using the syntax argumentName = value
. Consider the same function as before but with named arguments:
main.m49 chars4 lines
You can call this function with named arguments as follows:
main.m40 chars4 lines
In both cases, the arguments are evaluated before being passed to the function. If an argument is a variable or an expression, MATLAB evaluates it before passing it to the function.
gistlibby LogSnag