Programming Previous page   Next Page

M-File Programming


When you write a program in MATLAB, you save it to a file called an M-file (named after its .m file extension). There are two types of M-files that you can write: scripts and functions. Most of this chapter is about functions, as they are the more complex and useful of the two M-file types.
This chapter covers basic program development, describes how to write and call scripts and functions, and shows how to pass different types of data in a function call.

Program Development
Procedures and tools used in creating, debugging, optimizing, and checking in a program
Working with M-Files
Introduction to the basic MATLAB program file
M-File Scripts and Functions
Overview of scripts, simple programs that require no input or output, and functions, more complex programs that exchange input and output data with the caller
Function Arguments
Handling the data passed into and out of an M-file function, checking input data, passing variable numbers of arguments
Function Handles
Packaging the access to a function into a function handle, and passing that handle to other functions
Calling Functions
Calling syntax, determining which function will be called, passing different types of arguments, passing arguments in structures and cell arrays, identifying function dependencies


Previous page  Overloaded MATLAB Functions Program Development Next page

© 1994-2005 The MathWorks, Inc.