MATLAB Release Notes    

Programming and Data Types Features

MATLAB Interface to Java

MATLAB 6.0 provides an interface to Java that enables you to create objects from Java classes and call methods on those objects. You can use existing Java classes or create your own. See MATLAB Interface to Java for a summary of this feature. See Calling Java from MATLAB under "External Interfaces/API" in the online help, for full documentation.

Function Handles

The MATLAB language has a new data type called the function handle. You can create a handle to any MATLAB function and then use that handle as a means of referencing the function. A function handle is typically passed in an argument list to other functions, which can then execute, or evaluate, the function using the handle.

A MATLAB function handle is more than just a reference to a function. It often represents a collection of function methods, overloaded to handle different argument types. When you create a handle to a function, MATLAB takes a snapshot of all built-in and M-file methods of that name that are on the MATLAB path and in scope at that time, and stores access information for all of those methods in the handle.

When it comes time to evaluate the function handle, MATLAB considers only those functions that were captured within the handle when it was created. It is the combination of which functions are in the handle and what arguments the handle is evaluated with that determines which is the actual function that MATLAB dispatches to.

Function handles enable you to do all of the following. Each of these items is explained in more detail in Benefits of Using Function Handles in the online documentation:

You construct a function handle in MATLAB using the at sign, @, before the function name. The following example creates a function handle for the humps function and assigns it to the variable fhandle.

You pass the handle in the same way you would pass any argument. This example passes the function handle just created to fminbnd, which then minimizes over the interval [0.3, 1].

The fminbnd function evaluates the @humps function handle using the MATLAB feval function.

For more information, see Function Handles under "Programming and Data Types," in the MATLAB documentation.

Functions That Operate on Function Handles

The following MATLAB functions now operate on the function handle data type. The func2str, functions, and str2func functions are new to the MATLAB language.

Function
Purpose
feval
Evaluate a function through its handle
func2str
Construct a function name string from a function handle
functions
Display information about a function handle
isa
Determine if an object is a function handle
isequal
Compare function handles for equality
str2func
Construct a function handle from a function name string

CONTINUE Flow Control Statement

The continue statement passes control to the next iteration of the for or while loop in which it appears, skipping any remaining statements in the body of the loop. In nested loops, continue passes control to the next iteration of the for or while loop enclosing it.

The example below shows a continue loop that counts the lines of code in the file, magic.m, skipping all blank lines and comments. A continue statement is used to advance to the next line in magic.m without incrementing the count whenever a blank line or comment line is encountered.

New MATLAB Programming-Related Functions

The following programming-related functions are new in this release.

Function
Purpose
beep
Make your computer beep
genpath
Generate a path string that includes all directories below a named directory
iskeyword
Check if the input string is a MATLAB keyword
isvarname
Check if the input string is valid variable name
nargoutchk
Validate the number of output arguments
numel
Returns the number of elements in an object
rehash
Refresh function and file system caches
support
Open the MathWorks Technical Support Web page

Creating an Object That Inherits from Parent Classes Only

In MATLAB 5, the class function allows you to create a new object that inherits fields and methods from one or more parent classes. However, this new object acquires additional fields that belong to the structure_name argument passed in the call to class.

The syntax for this command is

In MATLAB 6.0, you can create a new object that contains no fields other than those that are inherited from the specified parent objects. Do this using the following syntax.

Code Length Restriction Removed

There is now no limit on the length of a line of M-code.

Running a Syntax Check on M-Files

You can run a check on the syntax of your M-files before executing the files; to do so, use the following command.

This command checks all M-files in the directories specified by the argument list for all warnings that MATLAB generates when reading the M-file into memory. All @class and private directories contained by the argument list directories will also be processed; class and private directories should not be supplied as explicit arguments to this function.

If no argument list is specified, all files on the MATLAB path and in the current working directory will be checked, except those in toolboxes.

If the argument list is exactly '-toolboxes', all files on the MATLAB path and in the current working directory will be checked, including those in toolboxes.

The following command displays the information given above.

This command can be especially helpful in locating missing separator characters that are now required between array elements. See Separators Are Now Required Between Array Elements.


  Mathematics Features Graphics Features