Programming Previous page   Next Page

Passing Certain Argument Types

This section explains how to pass the following types of data in a function call:

Passing Strings

When using the function syntax to pass a string literal to a function, you must enclose the string in single quotes, ('string'). For example, to create a new directory called myapptests, use

On the other hand, variables that contain strings do not need to be enclosed in quotes:

Passing Filenames

You can specify a filename argument using the MATLAB command or function syntax. For example, either of the following are acceptable. (The .mat file extension is optional for save and load):

If you assign the output to a variable, you must use the function syntax:

Specify ASCII files as shown here. In this case, the file extension is required:

Determining Filenames at Run-Time.   There are several ways that your function code can work on specific files without your having to hard-code their filenames into the program. You can

Passing Function Handles

The MATLAB function handle has several uses, the most common being a means of immediate access to the function it represents. You can pass function handles in argument lists to other functions, enabling the receiving function to make calls by means of the handle.

To pass a function handle, include its variable name in the argument list of the call:

The receiving function invokes the function being passed using the usual MATLAB calling syntax:

Previous page  Determining Which Function Is Called Passing Arguments in Structures or Cell Arrays Next page

© 1994-2005 The MathWorks, Inc.