
4 Programming
Scripts and Functions
In this section.. .
“Overview” on page 4-20
“Scripts” on page 4-21
“Functions” on page 4-22
“Types of Functions” on page 4-24
“Global Variables” o n page 4-26
“Passing String Arguments to Functions” on page 4-27
“The eval Function” on page 4-28
“FunctionHandles”onpage4-28
“Function Functions” on page 4-29
“Vectorization” on page 4-31
“Preallocation” on page 4-32
Overview
MATLAB is a pow erful programming language as well as an interactive
computational environment. Files that contain code in the M ATLAB language
are called M-file s. You create M-files using a text edito r, then use them as you
would any other MATLAB function or command.
TherearetwokindsofM-files:
• Scripts, which do not accept input arguments or return output arguments.
They operate on data in the w orkspace.
• Functions, which can accept input arguments and return output arguments.
Internal variables are local to the function.
If you’re a new MATLAB programmer, just create the M-files that you want
to try out in the current directory. As you develop more of your own M-files,
youwillwanttoorganizethemintootherdirectories and personal toolboxes
that you can add to your M ATLAB search path.
4-20
Kommentare zu diesen Handbüchern