Professional Documents
Culture Documents
Functions
90
1
120 60 Chapter 6
0.8
0.6
150 30
0.4
0.2
180 0
240 300
270
Objectives
Create and use MATLAB functions with both
single and multiple inputs and outputs
Create and use anonymous functions
Create and use function handles
Create and use subfunctions and nested
subfunctions
Section 6.1
Creating Function M-files
User defined functions are stored as
separate M-files
To use them, they must be in the current
directory
Syntax
All functions have a similar syntax,
whether they are built-in functions or user-
defined functions
Name
Input
A=cos(x)
Result
User-defined functions must start with a
function definition line
This function
has two
inputs
A user defined function with
multiple inputs
Functions with Multiple Outputs
Recall the
max
function
It returns
two results
This function return 3
output values