MATLAB Release Notes Previous page   Next Page

Programming Features

MATLAB 7.0 adds the following programming features and enhancements. For a list of new functions, see Summary of New Functions

Changes You Should Note

Other Programming Features

Case-Sensitivity in Function and Directory Names

Prior to this release, filenames for MATLAB functions and Simulink® models, (M, P, MEX, DLL, and MDL files) and also directory names were interpreted somewhat differently by MATLAB with regards to case sensitivity, depending upon which platform you were running on. Specifically, earlier versions of MATLAB handled these names with case sensitivity on UNIX, but without case sensitivity on Windows.

This release addresses the issue of case sensitivity in an effort to make MATLAB consistent across all supported platforms. By removing these differences, we hope to make it easier for MATLAB users to write platform independent code.

This change is more fully discussed in Case-Sensitivity in Function and Directory Names, under "Programming Upgrade Issues."

Differences Between Built-Ins and M-Functions Removed

MATLAB implements many of its core functions as built-ins. In previous releases of MATLAB, there have been several significant differences between the way MATLAB handles built-in and M-file functions. As of this release, MATLAB handles both types of functions the same. This change affects function dispatching and the output of the functions and which functions.

This change is more fully discussed in Differences Between Built-Ins and M-Functions Removed, under "Programming Upgrade Issues."

MATLAB Stores Character Data As Unicode

Prior releases of MATLAB represented character data in memory using a system default character encoding scheme that was padded out to 16-bits. This was the case both in memory and in MAT-files. If this data needed to be accessible to multiple users, each user's system had to use the same character encoding scheme. For those users whose default encoding scheme differed, the exchange of character-oriented information was not possible.

In Release 14, this limitation is removed by adopting the Unicode character data encoding scheme in mxArrays and their storage in MAT-files. For more information regarding Unicode, consult the Unicode Consortium web site at http://www.unicode.org.

Changes to save and matOpen

MATLAB writes character data to MAT-files using Unicode character encoding by default. You can override this setting and use the default character set for your system instead by doing one of the following:

See the individual reference pages for these functions for more information.

Character Rendering on Linux

Character data rendering has been improved for Linux operating systems that are configured with a UTF-8 default character set.

For More Information

For more information on saving character data using Unicode encoding, see Writing Character Data in the External Interfaces documentation. For information on the internal formatting of MAT-files, see the "MAT-File Format" document in the MATLAB documentation available in PDF format

New Calling Syntax for Function Handles

You can now call functions by means of their related function handles using standard calling syntax rather than having to use feval. When calling a function using its handle, specify the function handle name followed by any input arguments enclosed in parentheses.

For the parabola function shown here, construct a function handle h and call the parabola function by means of the handle:

When calling functions that take no input arguments, you must use empty parentheses after the function handle:

For purposes of backward compatibility, the use of feval to evaluate function handles is still supported in this release. See Function Handles and Backward Compatibility.

Arrays of Function Handles

Previous releases of MATLAB supported arrays of function handles. You created such an array using the [] operator, and indexed into the array with the () operator:

In Release 14, MATLAB supports arrays of functions handles using cell arrays. You create and index into a function handle array using the {} operator:

For purposes of backward compatibility, standard arrays of function handles are still supported in this release. See Function Handles and Backward Compatibility.

Anonymous Functions

Anonymous functions give you a quick means of creating simple functions without having to create M-files each time. You can construct an anonymous function either at the MATLAB command line or from within another function or script.

Refer to Anonymous Functions in the MATLAB Programming documentation for more complete coverage of this topic. For more information on anonymous functions, open the M-file anondemo.m in the MATLAB Editor by typing

Syntax

The syntax for creating an anonymous function from an expression is

where arglist is a comma-separated list of input variables, and expr is any valid MATLAB expression. The constructor returns a function handle, fhandle, that is mapped to this new function. Creating a function handle for an anonymous function gives you a means of invoking the function. It is also useful when you want to pass your anonymous function in a call to some other function.

You can use the function handle for an anonymous function in the same way as any other MATLAB function handle.

A Simple Example

To create a simple function sqr to calculate the square of a number, use

To execute the function, type the name of the function handle, followed by any input arguments enclosed in parentheses:

Since sqr is a function handle, you can pass it to other functions. The code shown here passes the function handle for anonymous function sqr to the MATLAB quad function to compute its integral from zero to one:

Arrays of Anonymous Functions

To store multiple anonymous functions in an array, use a cell array. See Arrays of Anonymous Functions in the MATLAB Programming documentation.

Examples

You can find more examples of how to use anonymous functions in MATLAB under Examples of Anonymous Functions."

Nested Functions

You can now define one or more functions within another function in MATLAB. These inner functions are said to be nested within the function that contains them. You can also nest functions within other nested functions.

Refer to Nested Functions in the MATLAB Programming documentation for more complete coverage of this topic. For more information on nested functions, open the M-file nesteddemo.m in the MATLAB Editor by typing

Writing a Nested Function

To write a nested function, simply define one function within the body of another function in an M-file. Like any M-file function, a nested function contains any or all of the usual function components. In addition, you must always terminate a nested function with an end statement:

Characteristics of Nested Functions

Two characteristics unique to nested functions are

Examples

You can find examples of how to use nested functions in MATLAB under Examples of Nested Functions."

Summary of New Functions

These functions are new in this release.

Function
Description
addtodate
Modify a particular field of a date number
genvarname
Construct valid variable name from string
intmax
Return largest possible integer value
intmin
Return smallest possible integer value
intwarning
Control state of integer warnings
isfloat
Detect floating-point arrays
isinteger
Detect whether an array has integer data type
isscalar
Determine if item is a scalar
isstrprop
Determine the content of each element of a string
isvector
Determine if item is a vector
mmfileinfo
Get information about multimedia file
recycle
Set option to move deleted files to recycle folder
restoredefaultpath
Restore default search path
strtrim
Remove leading and trailing whitespace from string
textscan
Read data from text file, convert and write to cell array
xlswrite
Write matrix to a Microsoft Excel spreadsheet

New Features in Regular Expression Support

This version of MATLAB introduces the following new features in regular expression support:

Refer to Regular Expressions in the MATLAB Programming documentation.

Functions that Use Regular Expressions

The who, whos, save, load, and clear functions now accept regular expressions as input. This feature enables you to be more selective concerning which variables they operate on.

For example, this statement saves to a MAT-file only those variables with a name that either starts with the letters A or B, or contains ten or more characters:

If the workspace contains the following four variables, two of the four meet the requirements of the regular expression:

When you perform the save operation and then check the contents of the MAT-file, you see that the variables with names that either start with A or have at least ten characters were saved:

Refer to the reference pages for these functions for more information and examples.

Changes to Error Message Format

The last two lines of MATLAB error messages have changed for Release 14. Error messages now

Each of these changes is discussed below. Examples show the errors generated by both the previous release (V6.5) and current release (7.0) of MATLAB for the purpose of comparison.

Display of Functions and Subfunctions

MATLAB now calls out the source of the error using a consistent format. One of the features of this format is that you can place the string of the message into other MATLAB commands. See Using the Error Message String as Input to Other Functions.

Errors Generated by the Primary Function.   Errors generated by the primary function of an M-file are displayed as shown below. In version 7.0, the path is not shown in most cases (private functions are one exception). Filename extension is also not shown. The failing line number is shown on third line.

In MATLAB V6.5 --

In MATLAB V7.0 --

Errors Generated by a Subfunction.   Errors generated by a subfunction of an M-file are displayed in the previous release and current release of MATLAB as shown below. Comments for primary functions apply here as well. Also, the name of the failing subfunction follows the > character instead of being put in parentheses.

In MATLAB V6.5 --

In MATLAB V7.0 --

Error Messages Display Nested Functions

This example shows an error that comes from a nested function (nestFun2) called by another nested function (nestFun1). It uses the following syntax, where the > character follows the name of the primary function and precedes the names of any nested functions.

In MATLAB V6.5 --

Nested functions are not supported prior to version 7.0.

In MATLAB V7.0 --

Using the Error Message String as Input to Other Functions

You can copy the text of theline that calls out the source of an error and use this string as input to some of the MATLAB debugging functions. The example shown below uses the string in a call to the dbstop function.

Copy the text that begins after

In MATLAB V6.5 --

This feature is not supported prior to version 7.0.

In MATLAB V7.0 --

Copy and paste text of this error message into the dbstop command:

Hot Link to the Source of an Error

Error messages now contain a blue-underlined hot link to the failing line of the M-file being executed.

Cell Array Support for String Functions

You can now pass a cell array of strings to the strfind function. MATLAB searches each string in the cell array for occurrences of the pattern string, and returns the starting index of each such occurrence.

Freestyle Date String Format

When converting between serial date numbers, date vectors, and date strings with the datenum, datevec, and datestr functions, you can specify a format for the date string from the Free-Form Date Format Specifiers table shown on the datestr reference page.

Additional Class Output From mat2str

The statement str = mat2str(A, 'class') creates a string with the name of the class of A included. This option ensures that the result of evaluating str will also contain the class information.

Change the 16-bit integer matrix to a string that includes 'int16'. Next, evaluate this string and verify that you get the same matrix that you started with:

datestr Returns Date In Localized Format

The statement str = datestr(..., 'local') returns the date string in a localized format. See the datestr reference page for more information.

Form and Locale for weekday

The weekday function now takes two new inputs that control the output format. These arguments enable you to get a full or abbreviated day name, and a local or US English output.

String Properties

Use the new isstrprop function to see what parts of a string or array of strings are alphabetic, alphanumeric, numeric digits, hexadecimal digits, lowercase, uppercase. white-space characters, punctuation characters, contain control characters, or contain graphic characters.

For example, to test for alphabetic characters in a two-dimensional cell array, use

Bit Functions on Unsigned Integers

MATLAB bit functions now work on unsigned integers. Instead of using flints (integer values stored in floating point) to do you bit manipulations, consider using unsigned integers. See Bit Functions Now Work on Unsigned Integers in the MATLAB Mathematics release notes.

nargin and nargout Now Work on Built-Ins

In this release, you can now use the nargin and nargout functions to find out how many inputs and outputs are supported by a built-in function:

nargchk Has a New Format for Error Messages

When the nargchk function detects an error condition, it returns information on the error in either a string or a MATLAB structure. Use one of these two command syntaxes to specify which format to return. If neither is specified, nargchk returns a string:

The return structure has two fields: the message string, and a message identifier. When too few inputs are supplied, these fields are

When too many inputs are supplied, the structure fields are

Using strtok on Cell Arrays of Strings

You can now use the strtok function on a cell array of strings. When used with a cell array of strings, strtok returns a token output that is also a cell array of strings, each containing a token for its corresponding input string.

See the strtok reference page to see an example of how this works.

Protecting Files from Unwanted Deletion

To protect yourself from unintentionally deleting any files that you want to keep, use the new recycle function to turn on file recycling. When file recycling is on, MATLAB moves all files that you delete with the delete function to either the recycle bin (on the PC or Macintosh) or a temporary folder (on UNIX). When file recycling is off, any files you delete are actually removed from the system.

You can turn recycling on for all of your MATLAB sessions using the Preferences dialog box (Select File -> Preferences -> General). Under the heading Default behavior of the delete function, select Move files to the Recycle Bin.

inmem Returns Path Information

The inmem function now returns not only the names of the currently loaded M- and MEX-files, but the path and filename extension for each as well. Use the -completenames option to obtain this additional information:

Accessing Cell and Structure Arrays Without deal

In many instances, you can access the data in cell arrays and structure fields without using the deal function. Here is an example that reads each of the cells of a cell array into a separate output:

Use either of the following to access the cells in C:

Here is an example that reads each of the fields of a structure array into a separate output:

Use either of the following to access the name field:

Calling Private Functions From Scripts

You can now invoke a private function from a script, provided that the script is called from another M-file function, and that the private function being called by the script is within the scope of this M-file function.

New Features for Nondouble Data Types

The section New Nondouble Mathematics Features describes new features affecting the nondouble (single and integer) data types. These changes affect single and integer arithmetic operations, and also conversion of single and double data types to integers.

Unicode-Based Character Classification

Unicode-based character classification APIs are now provided in MATLAB. The new character classification functions work with any locale or language and resolve all locale-specific issues that existed in prior releases.

Compressed Data Support in MAT-Files

The save function compresses your workspace variables as they are saved to a MAT-file. When writing a MAT-file that you will need to load using an earlier version of MATLAB, be sure to use the save -v6 command. When you use the -v6 switch, MATLAB saves the data without compression and without Unicode character encoding. This makes the resulting file compatible with MATLAB Version 6 and earlier.

You can also compress data when using MAT-file interface library functions (matPut*) to write to a MAT-file by opening the file with the command matOpen wz. See the section Compressing Data in the save reference page for more information on this feature.

Comprehensive Function for Reading Text FIles

The new textscan function reads data from an open text file into a cell array. MATLAB parses the data into fields and converts it according to conversion specifiers passed to textscan in the argument list.

The textscan function is similar to textread but differs from textread in the following ways:

Saving Structures with the save Function

Two new syntaxes for the save function enable you to save individual fields of a structure to a file. See the function reference for save for more information.

To save all fields of the scalar structure s as individual variables within the file, myfile.mat, use

To save as individual variables only those structure fields specified (s.f1, s.f2, ...), use

New Data Import/Export Features

MATLAB includes the following new features for importing and exporting data.

New Features in the xlsread Function

The table below shows new input and output arguments to the xlsread function. See the function reference for xlsread for more information. With the exception of the basic input argument, these arguments are supported only on computer systems capable of starting Excel as a COM server from MATLAB.

New Input Arguments
Description
-1
Opens the Excel file in an Excel window, enabling you to interactively select the worksheet to be read and the range of data to import from the worksheet.
range
Reads data from the rectangular region of a worksheet specified by range.
basic
Imports data from the spreadsheet in basic import mode.


New Output Argument
Description
rawdata
Returns unprocessed cell content in a cell array. This includes both numeric and text data.

New Features in dlmwrite Function

The dlmwrite function now has several new input arguments plus an optional attribute-value format in which to enter these arguments. You can now enter input arguments to dlmwrite in an attribute-value format. This format enables you to specify just those arguments that you need and omit any others. This new syntax for dlmwrite is

The former syntax for dlmwrite is still supported for arguments that were available in earlier versions of MATLAB.

The table below shows new input arguments to the dlmwrite function. You must specify these new arguments using the attribute-value format. See the function reference for dlmwrite for more information.

Attribute
Value
append
Either overwrite or append to the file
delimiter
Delimiter string to be used in separating matrix elements
newline
Character(s) to use in terminating each line
roffset
Offset, in rows, from the top of the destination file to where matrix data is to be written
coffset
Offset, in columns, from the left side of the destination file to where matrix data is to be written
precision
Numeric precision to use in writing data to the file

For example, to export matrix M to file myfile.txt, delimited by the tab character, and using a precision of six significant digits, type

Importing Complex Arrays

The csvread, dlmread, and textscan functions import any complex number as a whole into a complex numeric field, converting the real and imaginary parts to the specified numeric type. Valid forms for a complex number are

Form
Example
±<real>±<imag>i|j
5.7-3.1i
±<imag>i|j
-7j

Using imread to Import Subsets of TIFF Images

Using the imread function with the 'PixelRegion' parameter, you can now read in portions of an image stored in TIFF format. As the value of this parameter, you specify a cell array containing two vectors: ROWS and COLS. Each vector can either be a two-element vector specifying the extent of the region, [START STOP], or a three-element vector that enables downsampling, [START INCREMENT STOP].

When used with tiled images, 'PixelRegion' subsetting can improve memory usage and performance because it only reads in the tiles that encompass the region. For example, in the following figure, if you specify the region defined by the box, imread would only read in tiles 1, 2, 4, and 5.

Getting Information about Multimedia Files

MATLAB now includes a function, named mmfileinfo, that returns information about the contents of a multimedia file. The file can contain audio data, video data, or both.

This function is only available on Windows platforms.

All-Platform Audio Recording and Playback

The MATLAB audiorecorder and audioplayer functions can now be used on Windows and UNIX platforms. These functions were previously only available on Windows systems.

FTP File Operations

From within MATLAB, you can connect to an FTP server to perform remote file operations. For more information, see the ftp reference page.

Web Services (SOAP)

MATLAB can now consume Simple Object Access Protocol-based (SOAP) Web services with the createClassFromWSDL function. For more information, see Using Web Services in MATLAB in the online documentation.

MATLAB Performance Acceleration

Release 13 introduced a new performance acceleration feature built into MATLAB. Enhancing performance in MATLAB is an ongoing development project that continues to show significant improvements in the performance of MATLAB programs.

The Performance Acceleration documentation written for Release 13 included suggestions on specific techniques to make the most of this feature. In this release, many of those techniques are no longer necessary. This documentation has been replaced with more general suggestions on how to improve the performance of your programs.

"Using MATLAB" Documentation Is Now Three Books

Due to the increasing size of the printed "Using MATLAB" manual, we have divided it up into three separate printed books in version 7.0 to make it more manageable. The titles for these books (and their corresponding headings in the MATLAB Help Browser) are

The online structure of this documentation is very similar to what it has been in previous releases, although some topics are now covered more thoroughly. We hope that you find this new format easier to use.


Previous page  Mathematics Features Graphics and 3-D Visualization Features Next page

© 1994-2005 The MathWorks, Inc.