MATLAB Release Notes |
Programming and Data Types Issues
Evaluating Function Names
The feval
function can be used with either function handles or function name strings. Evaluation of function handles is preferred over evaluation of the function name. For example, of the following two lines of code that evaluate the humps
function, the second is considered to be the preferable mechanism to use.
feval('humps', 0.5674); % Uses a function name string feval(@humps, 0.5674); % Uses a function handle
To support backward compatibility, feval
still accepts a function name string as a first argument and evaluates the function named in the string. However, function handles offer you the additional performance, reliability, and source file control benefits listed in the earlier section Programming and Data Types Features.
Argument Name Length for feval, load, and save
Most names in MATLAB are truncated to 31 characters. In previous versions of MATLAB, this was not true for arguments passed to the feval
, load
, and save
functions. As a result, MATLAB was able to distinguish between names passed into these functions when these names were identical up to the thirty first character but unique at some point after that.
In MATLAB 6.0, arguments (other than filenames) that are passed to feval
, load
, and save
are truncated to a maximum of 31 characters. If your code uses names in which the first 31 characters are identical, MATLAB will no longer distinguish between these names within these functions.
Filenames do not hold to this rule. MATLAB uniquely identifies files with names of any length.
Limit on Line Length of M-code Removed
There is no longer any limit on the length of a line of M-code in MATLAB.
feval Accepts Only Simple Function Names
In previous versions of MATLAB, you could call feval
passing the full path to the function to be evaluated. You could also call a subfunction or private function directly using this method. For example, the following command executes a subfunction that is defined within the file, subfile
.
In MATLAB 6.0, feval
accepts only simple function names. To evaluate subfunctions and private functions from beyond their usual scope, you can use function handles.
Assigning to an Empty Structure Field
Attempting to assign a structure to a field of another structure now results in an error if both of the following conditions are true:
mystruct.emptyfield = []; mystruct.emptyfield(1) = struct('f1', 25); ??? Conversion to double from struct is not possible.
This operation did not return an error in previous versions of MATLAB.
Comparing With an Empty Structure Field
Attempting a string comparison between a string and a structure field now results in an error, if all of the following conditions are true:
strcmp
using an array index.
This operation did not return an error in previous versions of MATLAB.
Separators Are Now Required Between Array Elements
MATLAB 5 allowed two or more elements of a cell array, vector, or matrix to appear together without any separating text such as a comma or whitespace, under certain circumstances. For example, the following were all legal expressions.
[[1][2]] % equivalent to [ 1 2 ] ['hello'sprintf(' world')] % equivalent to [ 'hello world' ] {{1}fft(2)} % equivalent to { {1} 2 }
MATLAB 6.0 issues a warning if it detects this situation upon first loading the M-file into memory. Future versions of MATLAB will likely error at that point instead. To remedy the situation, place a comma or whitespace between the elements of the cell array, vector or matrix, as in
The following command displays the information given above.
Note The section Running a Syntax Check on M-Files describes how MATLAB can help you locate missing element separators in your M-files. |
Logical AND and OR Precedence
Starting in MATLAB 6.0, the precedence of the logical AND (&) and logical OR (|) operators now obeys the standard relationship, where AND has a higher precedence than OR. This precedence agrees with the formal rules of Boolean algebra as implemented in most other programming languages, as well as in Simulink and Stateflow.
Previously, MATLAB would incorrectly treat the expression
The only case where the new precedence will impact the result obtained is when | appears before & within the same expression (without parentheses). For example,
In MATLAB 5.3 and earlier, this statement would yield 0, being evaluated as
In MATLAB 6.0 and beyond, this expression yields a 1 as the result, being evaluated as
Note We strongly recommend that you add parentheses to all expressions of this form to avoid any potential problems with the interpretation of your code between different versions of MATLAB. |
A feature has been provided to allow the system to produce an error for any expression that would change behavior from the old to the new interpretation.
feature('OrAndError', 0) % Warning for any expression that % changed behavior (default) feature('OrAndError', 1) % Error for any expression that % changed behavior
Breaking From Try-Catch in a Loop
The MATLAB break
function terminates the execution of a for
or while
loop. If a for
or while
loop contains a try
- catch
statement, with a break
placed within the try
- catch
, the break
statement terminates the for
or while
loop, not the try
- catch
.
In the following example, a break
has been placed in a try
- catch
statement and the try
- catch
is within a for
loop. In MATLAB 5, execution of the break
causes an incorrect branch from the try
to the line, x = 5
. The for
loop is not terminated, in this case.
In MATLAB 6.0, execution of the break
within the try
- catch
terminates the for
loop. The next line executed following the break
is y = 10
.
for i = 1:10 try <statement> break catch <statement> end x = 5 % Break to here in MATLAB 5 end y = 10 % Break to here in MATLAB 6.0
Specifying Field Names with setfield and getfield
The setfield
and getfield
functions set and get the value of a specified field in a MATLAB structure array. In MATLAB 5, you could use the following undocumented syntaxes to set fieldn
to the value, newvalue
and to read back that value.
These syntaxes are not supported in MATLAB 6.0. You should use the following instead.
Using GETFIELD on a Structure Array
The getfield
function returns the contents of a specified field in a MATLAB structure array. In MATLAB 5, you would get an error if you requested more than one return value on a single getfield
call. For example, the following call to getfield
requests the contents of the x
field for all three elements of the structure array, a
.
In MATLAB 6.0, requesting more than one output value from getfield
returns a single output value and does not result in an error. The value returned is the first of all output values requested in the call. In the example above, getfield
now returns the contents of a(1).x
, because that is the first field to which (a,'x')
applies.
You can obtain the contents of another structure array element by specifically indexing to that element. For example:
Temporary Variables Are Anonymous
Individual cells of a cell array, fields of a MATLAB structure, and all temporary variables are now guaranteed to be anonymous.
For example, the following function returns the name of the first input argument passed to myfun
.
In MATLAB 5, a temporary variable, used to pass the value of eval('x')
, retains the variable name, x
. In MATLAB 6.0, this variable is anonymous.
x = [1 2 3]; myfun(eval('x'')) % Running MATLAB 5, ... x % the output is x myfun(eval('x'')) % Running MATLAB 6.0, ... '' % the output is ''
This change may result in a small difference in the size of some MAT files.
Platform Name Changes for the computer Function
The names returned by the computer
function for some UNIX platforms have changed for MATLAB 6.0. If you have code that uses the computer
function for special handling on some UNIX platforms, that code may behave differently because of these platform name changes.
Platform |
Pre-6.0 String |
String for MATLAB 6.0 |
Linux |
LNX86 |
GLNX86 |
SGI |
SGI |
SGI (no change) |
SGI64 |
SGI64 |
SGI |
HPUX 11.x |
HP700 |
HPUX |
HPUX 10.20 |
HP700 |
HP700 (no change) |
Processes and Memory Usage on Linux
On Linux, you may notice that MATLAB can start up a large number of processes, even to handle simple tasks. These are actually threads, but due to the "one process per thread" model on Linux, they appear as processes. When you use the ps or top commands in Linux to show the processes running on your system, you will see each of these threads listed as a separate process.
It is not uncommon for Linux to create a large number of threads for an application. Even a simple Java program using AWT and native threads on Linux will create nine threads.
Also displayed is the amount and percentage of memory used by each thread. You should be aware that the memory used by the threads started by MATLAB is shared between threads. The memory consumption reported for each thread in this display actually represents the total memory used by all of the MATLAB threads together.
Obsolete Functions
The following MATLAB functions have either been renamed or have become obsolete. For backwards compatibility, they have not been removed from the language at this time. However, these functions may be removed in a future release, so you are encouraged to discontinue use of the functions, or use the functions that replace them.
Function |
Description |
errortrap |
Replace with try ... catch |
flops |
Floating-point operation count. Now returns 0 . |
fmin |
Minimize a function of one variable. Replace with fminbnd . See instructions for converting your code in "Function Functions" in the MATLAB documentation. |
fmins |
Minimize a function of several variables. Replace with fminsearch . See instructions for converting your code in "Function Functions" in the MATLAB documentation. |
foptions |
Default parameters used by the optimization routines. Replace with optimget , optimset . See instructions for converting your code in "Function Functions" in the MATLAB documentation. |
interp4, interp5, interp6 |
Various two-dimensional data interpolation. Use interp2 instead. |
isdir |
Replace with exist |
isieee |
Return logical true (1 ) on machines with IEEE arithmetic and logical false (0 ) on machines without IEEE arithmetic. Now returns 1 in all cases. |
isstr |
Replace with ischar |
meshdom |
Generate X and Y arrays for three-dimensional plots. Use meshgrid instead. |
nnls |
Nonnegative least squares. Replace with lsqnonneg . See instructions for converting your code in "Function Functions" in the MATLAB documentation.
|
quad8 |
Numerically evaluate integral. Replaced by |
saxis |
Sound axis scaling. Now has no effect on the output of |
setstr |
Replace with char |
str2mat |
Replace with char |
table1 |
One-dimensional table lookup. Use |
table2 |
Two-dimensional table lookup. Use |
The errortrap Function Is Disabled But Not Removed
The errortrap
builtin function is obsolete in MATLAB 6.0. It is disabled, but has not been removed from the language for purposes of backward compatibility.
Specifying Ordinary Differential Equation (ODE) Problems
The ODE problem components that were passed to the solver through an ODE file now are passed directly as arguments or need to be specified in an options structure. The new syntax is
where odefun
, tspan
and y0
are required arguments. See the ODE solver and odeset
reference pages for details.
MATLAB 6.0 supports use of an ODE file for backwards compatibility, but new functionality is available only with the new syntax.
Output from Background and Foreground Commands (UNIX)
In Release 12 on UNIX platforms, a background command (i.e., any system command after which you add a &
), such as
no longer produces any output. Prior to Release 12, a background command sent output to the command window.
If you need to see the output from a command, either do not make the command a background command (i.e., remove the &
), or run the background command in a separate xterm. To start another xterm, issue the following command.
In Release 12, foreground functions (i.e., non-background functions) send their output to the diary, if the diary
function has been issued. The output is also displayed in the command window (prior to Release 12, foreground function output was only displayed in the command window).
matlab_helper Process
To make the !
and unix
commands operate more efficiently, in Release 12 MATLAB creates a secondary process, called matlab_helper
, at startup.
This matlab_helper
contains those elements of MATLAB necessary to run the !
and unix
commands.
Development Environment Issues | External Interfaces/API Issues |