Matlab Tutorial Session 4
This tutorial session covers the following topics
Variable number of arguments in functions
Advanced input and output including file input and output
Output for Tecplot from Matlab, Reading a Tecplot datafile
Next tutorial will cover (i) cell arrays and structures,
(ii) differential equation solvers,
(iii) introduction to symbolic math toolbox.
Review of Session 3
Functions in Matlab are written in a separate M-file.
This M-file begins with the
may be a single variable (such as
), or there
may be multiple output variables specified as a vector (such as
The input and output variables are not pre-typed to be integers, strings etc.
function is written assuming proper types of variables and it is up to the user (or
calling program) to provide the function with proper arguments and collect the
Otherwise the user will experience error in execution.
A function has no access to any variables outside it.
Everything required must be
passed as arguments.
There is an exception to this, which is to specifically define
certain variables in the workspace as
discussed in this session.
Function M-file must be in the current directory or in matlab path so that matlab
can find it.
Otherwise matlab issues an error that such a function does not exist.
Subfunction may be placed in a function M-file at the end.
But they cannot
access the main function’s variables.
They must again be passed everything as
A function may be executed by the following syntax in the program:
[out1, out2 , …, outM] = functionname ( inp1, inp2, …, inpN)
or by using the feval command
[out1, out2 , …, outM] =