User-defined functions are similar to the MATLAB predefined functions. A function is a MATLAB program that can accept inputs and produce outputs. A function can be called or executed by another program or function. Code for a function is done in an Editor window or any text editor same way as script and saved as m-file. The m-file must have the same name as the function.
The declaration statement 'function' is used to define the file as a function. It must be typed in lower case letters. Rules for giving function name is same as the rules for variable names.
Input arguments are typed in side the parentheses ( ). They are used to transfer data into function from calling program. Can be zero or more input arguments.
Output arguments are typed inside the square brackets [ ]. They are used to transfer data out of function to calling program. Can be zero or more output arguments. It is important to give a meaningful variable names.
No comments:
Post a Comment