MATLAB Release Notes    

Programming and Data Types Upgrade Issues

The issues involved in upgrading from MATLAB 6.1 to MATLAB 6.5, in terms of programming and data types features, are discussed below. MATLAB 6.5 introduces important changes to the inner structure of MATLAB that may affect existing programs. These changes are

Maximum Name Length Changed for Variables, Functions, Files

Prior to this release, the length of MATLAB identifiers (variable names, function and subfunction names, structure fieldnames, M-file names, MEX-file names, and MDL-file names) was restricted to 31 characters. Names using more than 31 characters were either truncated by MATLAB or caused a warning or error to be generated.

In MATLAB 6.5, any of these names can be up to 63 characters long.

A new function, namelengthmax, returns the maximum length for MATLAB identifiers.

If you have MATLAB programs that hard-code the maximum identifier length as 31, you should replace these hard-coded limits with a call to namelengthmax.

If you use identifiers that exceed 63 characters, MATLAB issues a warning and truncates any characters beyond the 63rd.

Characters Beyond 31 Are No Longer Ignored.   In previous versions of MATLAB, if you had two or more long identifiers in which the first 31 characters were identical, MATLAB ignored any characters beyond the thirty first and thus recognized only one of the identifiers. For example, these two Stateflow filenames

both appeared to MATLAB 6.1 as shown below, and MATLAB recognized only one of the files:

In MATLAB 6.5, with the maximum MDL-file name length increased to 63, MATLAB recognizes both files. You should be aware of this change, as it could possibly lead to unexpected behavior.

Warning for Identifiers Longer Than 31.   In MATLAB 6.5, if you use an identifier that exceeds the previous limit of 31 characters, MATLAB can optionally generate a warning of the form:

This warning is disabled by default. You can enable it by typing

Warning for Identifiers Longer Than namelengthmax.   If you specify an identifier that exceeds the new character limit, MATLAB generates the following warning:

This warning is enabled by default. You can disable it by typing the following command. However, we strongly encourage you to leave it enabled:

MATLAB Toolbox Functions Updated.   MATLAB toolbox functions, such as isvarname, have been updated in MATLAB 6.5 to make use of the namelengthmax function, and thus return the correct values.

Effect On P-Code and MEX-files.   You should recompile the following files:

The logical Attribute Is Now a Class

In previous versions of MATLAB, logical was an attribute of any numeric data type. This is illustrated in the following example (executed in MATLAB 6.1), where b = a > 10 produces a double array with a logical attribute:

In MATLAB 6.5, logical is a first class data type and MATLAB class. The class hierarchy diagram below shows logical to be a class, equivalent to other first class types like character and cell arrays.

The same example, executed in MATLAB 6.5, produces a result of class logical array:

Effect on Related Functions.   The table below compares the results obtained from a number of functions that operate on logical types. The variable a in the table is derived as follows:

Valid logical Values.   logicals can only have the values 0 and 1. When you convert real finite values other than 0 or 1 to logical, MATLAB gives them a logical 1 value and issues a warning message:

Behavior of islogical is Unchanged.   Note in the table above that islogical continues to return 1 for a logical array, as it did in previous releases for arrays with a logical attribute.

Array Manipulation.   All generic array manipulation functions (e.g., subscripting, reference, assignment, concatenation, size, length, numel, ndims, permute, diag, etc.) work as they do in MATLAB 6.0, subject to the behaviors described in this section.

Boolean Functions.   All Boolean functions (e.g., and, or, not, xor, any, all) work as they do in MATLAB 6.0, subject to the behaviors described in this section.

MAT-Files.   MAT-files created with earlier versions of MATLAB that contain logical arrays will load correctly in MATLAB 6.5. Values other than 0 or 1 will be converted to 1's. A double array with a logical attribute, when loaded in MATLAB 6.5, will be a logical array.

Mixed-Mode Arithmetic.   Mixed-mode arithmetic (e.g., arithmetic involving a logical and a double) dispatches to the function registered for the nonlogical data type. The logical is converted to that type and the operation proceeds. This behavior is fully backward compatible with how MATLAB works in MATLAB 6.0.

Converting logical to double.   You can use the double function to convert a logical array to a double array:

Indexed Assignment.   As a rule, MATLAB data types are preserved on indexed assignment. This now holds true for logical, as it is now a MATLAB data type.

This example creates an empty array of type logical. The indexed assignment to double that follows, (a(1) = 1), does not change the type to double. Its logical type is preserved:

Passing NaN or Complex to logical Functions.   Attempting to pass NaN or complex values to an if or while statement, or to and, or, not, or logical, now consistently generates an error:

Creating Logical Matrices with the sparse Function.   Previously, when creating sparse logical matrices, the sparse function accumulated entries when it encountered repeated indices. For example,

In MATLAB 6.5, sparse now returns an error, because the only valid logical values are 0 and 1:

Changes to Definition of "Truth"

As MATLAB has evolved, its definition of truth has become complicated and inconsistent. One goal of MATLAB 6.5 is to present a simple and self-consistent definition of truth that applies in all situations.

This change affects the following types of operations.

Comparing Empty with Empty or Scalar.   MATLAB now returns an empty array ([]) when you compare two 0-by-0 empty arrays, or a 0-by-0 empty array with a scalar. This behavior also affects comparisons performed inside if and while statements.

Comparing two 0-by-0 empty arrays:

Comparing a 0-by-0 empty array with a scalar:

This behavior is now consistent with all other binary operators (e.g., >, <, ~=, +, -, .*, etc.).

Comparing Empty with Nonscalar.   MATLAB now returns a dimension mismatch error when you compare a 0-by-0 empty array with a sized array:

Using NaN with any or all.   The any and all functions now ignore NaN. Thus any now returns 0 for a vector having NaNs as its only nonzero elements. The behavior of all is unaffected by this change, but it means that any and all now behave consistently with other reduction operators like min and max:

Interaction with Objects.   In previous versions of MATLAB, passing a user-defined object as the argument to if or while caused the interpreter to call the object's double method (assuming it had one) in order to convert it to something whose truth could be determined. MATLAB 6.5 handles this situation by looking first for a logical method for the object and, upon failing to find one, calls its double method, if one exists.

If you have objects that will participate in truth evaluation, you should provide a logical method for those objects. The logical method must return 0 or 1 (false or true).

The sparse Class Is Now an Attribute

In previous versions of MATLAB, sparse was a first class data type and MATLAB class (subclass of double). This is illustrated in the following example (executed in MATLAB 6.1), where sparse(eye(3)) produces a sparse array:

In MATLAB 6.5, sparse becomes an attribute of a MATLAB class. The class hierarchy diagram below represents the MathWorks long-range plan for sparse, where full and sparse are attributes of all MATLAB classes.

The same example, executed in MATLAB 6.5, produces a double array with a sparse attribute:

Effect on Related Functions.   The table below compares the results obtained from a number of functions that operate on sparse arrays. The variable a in the table is derived as follows:

Behavior of issparse is Unchanged.   Note in the table above that issparse continues to return 1 for arrays with a sparse attribute, as it did in previous releases for sparse arrays.

Arithmetic Operations.   Arithmetic operations continue to work on sparse doubles as they do today.

Determining Storage Type.   Make sure that your programs do not use class or isa to determine if a matrix uses sparse storage. Use issparse instead. It is both simpler and faster.

Methods in @sparse Directories.   If you have written your own algorithms for dealing with sparse matrices and placed them in an @sparse directory, MATLAB will not access them because sparse is no longer a class.

MAT-Files.   MAT-files created with earlier versions of MATLAB that contain sparse arrays will load correctly in MATLAB 6.5. A sparse array, when loaded in MATLAB 6.5, will be a double array with a sparse attribute, or a logical array with a sparse attribute if the array originally had the logical attribute. (See The logical Attribute Is Now a Class for information on changes to logical).

Converting to Full.   Use full(x) instead of double(x) to ensure that variable x is full. The double function no longer removes the sparseness of an array:

Use full instead to make the array full:

Testing for full arrays.   You should no longer use the following statement to test whether an array is full (nonsparse). Because the sparse class has been removed in MATLAB 6.5, this statement now returns 1 for both full and sparse arrays:

In place of the above statement, use the following to test for a full array:

For example, create a sparse array, s, and test to see if it is a full array:

Indexed Assignment.   As a rule, MATLAB data attributes are not preserved on indexed assignment. This now holds true for sparse, as it is now an attribute.

This example creates a sparse double array. The indexed assignment to a full double that follows, (s(:) = rand(3)), removes the sparse attribute from the array:

Logical Indexing and find

The following two statements are intended to be equivalent in MATLAB. However, prior to this release, the statements were not equivalent in the case where a is nondouble and b contains only zeros:

This has been fixed in this release. For the a and b shown here, the three equations that follow return the same result:

As a result of this fix, you can now use either of the last two, simpler forms in place of the form that requires the use of find.

Warning Control Upgrade Issues

See the section on Warning Control Features in these Release Notes for information on how you can control the way MATLAB handles the selected warnings in your programs.

Changes to Functionality.   In some case, these changes to warning control will affect warning statements that currently exist in your code. The following two tables present how Versions 6.0 and 6.5 of MATLAB respond to MATLAB 6.0 warning syntax.

This table shows the MATLAB 6.0 behavior.

MATLAB 6.0 Syntax
MATLAB 6.0 Behavior
warning backtrace
warning on all; Enable backtraces.
warning backtrace off
warning on all; Disable backtraces.
warning backtrace on
warning on all; Enable backtraces.
warning off backtrace
warning on all; Disable backtraces.
warning on backtrace
warning on all; Enable backtraces.
warning debug
warning on all; dbstop if warning
warning debug off
warning on all; dbclear if warning
warning debug on
warning on all; dbstop if warning
warning off debug
warning on all; dbclear if warning
warning on debug
warning on all; dbstop if warning
warning once
warning once ... <each-HG-back-compat-message-identifier>
warning always
warning always ... <each-HG-back-compat-message-identifier>
warning
ans gets one of on, off, debug, or backtrace.
s = warning(...)
s gets one of on, off, debug, or backtrace.
Process inputs (if any) as above.
[s, f] = warning(...)
s gets one of on, off, debug, or backtrace.
f gets one of once or always. Process inputs
(if any) as above.

For backward compatibility, MATLAB will continue to accept every usage of warning shown in the left column of the table above. However, some changes will be made to their actual behavior, as shown in the table below.

This table shows the MATLAB 6.5 behavior in response to MATLAB 6.0 warning command syntax.

MATLAB 6.0 Syntax
MATLAB 6.5 Behavior
warning backtrace
Enable backtraces.
warning backtrace off
Disable backtraces.
warning backtrace on
Enable backtraces.
warning off backtrace
Disable backtraces.
warning on backtrace
Enable backtraces.
warning debug
dbstop if warning
warning debug off
dbclear if warning
warning debug on
dbstop if warning
warning off debug
dbclear if warning
warning on debug
dbstop if warning
warning once
Warning - warning frequency is no longer supported.
warning always
Warning - warning frequency is no longer supported.
warning
warning query all; (doesn't assign to ans).
s = warning(...)
s = warning('query', 'all');
then process inputs (if any) as above.
[s, f] = warning(...)
Warning - warning frequency is no longer supported.

Outputs Returned by Warning.   Prior to MATLAB 6.5, warning returned up to two outputs: state and frequency. Neither of these is meaningful anymore, as there is no longer neither a single warning state nor a single warning frequency to return.

The frequency output is now disallowed. MATLAB generates a warning if you request this output.

The warning function now returns a structure instead of a string for the state output. Any existing code that uses this output should continue to function normally, but should be examined to make sure that the state value is properly interpreted in this new context.

Formatted Error and Warning Strings

For backward compatibility, if only one input is passed to error or warning, MATLAB treats it as a fixed string, not a format string. See Formatted String Conversion in Errors and Warnings in the MATLAB documentation.

getfield and setfield Superseded

Since dynamic field names improve on the getfield and setfield, these two functions will eventually be removed from the MATLAB language. In MATLAB 6.5, getfield and setfield will generate a warning message encouraging you to use dynamic field names instead. See the section, Dynamic Field Names for Structures for more information on this.

New Behavior in break

The break function is intended to be used within a for or while loop. Use of break outside of a loop results in a warning being issued.

isequal and Structure Field Creation Order

When comparing structures with isequal, MATLAB no longer considers the order in which the fields of the structures were created in determining equality. See Example 2 on the isequal reference page.

Set Operations on Cell Arrays of Strings

The intersect, setdiff, and setxor functions have been modified to handle cell arrays of strings having one of more trailing spaces in a manner that is consistent with its handling of other array types. These set functions no longer ignore trailing spaces when doing the comparison. See the examples below:

Prior to MATLAB 6.5
MATLAB 6.5
intersect({'A'}, {'A '})
ans =
'A'
intersect({'A'}, {'A '})
ans =
{}
setdiff({'A'}, {'A '})
ans =
{}
setdiff({'A'}, {'A '})
ans =
'A'
setxor({'A'}, {'A '})
ans =
{}
setxor({'A'}, {'A '})
ans =
'A' 'A '

Using mat2cell on an Empty Array

If you invoke mat2cell on an empty array, the function now returns an empty cell array rather than issuing an error. This requires that all zero dimensions of the empty input array have a corresponding mat2cell argument equal to [].

In the following example, the third input argument to mat2cell specifies how MATLAB is to divide up the second dimension of the input array, X, in the resultant cell array. (See the mat2cell reference page for help on syntax.) Because the second dimension of X is of zero size, the only valid division specifier is [].

Concatenating with Empty Arrays

Empty arrays in concatenation operations can now affect the data type of the output. The only time you are likely to see this is when concatenating doubles and logicals. In previous versions of MATLAB, the example shown below returned a double array with a logical attribute. Now it returns a double because the empty double input is no longer ignored:

Concatenating Empty Cell Arrays.   You cannot concatenate an empty cell array with numeric or character values:

Function Names Redefined As Variable Names

Under the conditions listed below, if you define a variable using a name that already belongs to a function, MATLAB issues the following warning message:

This warning is issued only when all of the following conditions are true:

For example, the first line of the function shown below uses the term i to call the MATLAB function that returns the complex constant. Some time later, in the for loop, the function code redefines i so that MATLAB now interprets it as a variable name, and assigns to the variable the values 1:10.

When MATLAB compiles this M-file function, it issues the warning message shown above. The reason for the warning is illustrated in the last line of the code shown in the example. The statement 32 + i does not add the complex constant i to 32 as intended, but instead adds the value 10 to 32. This is because the opening for loop statement redefined the name i as a variable name and the last value assigned to that variable was 10.

Note that this is a compile-time warning only. M-files run for the first time in a MATLAB session, or run after being cleared from memory (e.g., by clear functions) may issue this warning. M-files that are executed from cache do not.

Specifying More Outputs Than a Function Defines

A function call that requests more output values than are generated by the function being called now returns an error instead of a warning. Consider the function below that declares two outputs in the function definition line and assigns a value to one of them.

Calling this function with one output specified in the call completes successfully. Calling the function with two outputs specified returns an error. Even though two outputs are declared in the function definition line, only one output is generated in the function body.

In previous versions of MATLAB, this type of call resulted in a warning. As a result, execution of the function continued and assignment to output variable A completed successfully.

In MATLAB 6.5, this type of call generates an error and aborts execution of the M-file. As a result, A remains undefined.

Consistent Handling of Subscripting Errors

The way in which MATLAB handles invalid subscripting is more consistent in MATLAB 6.5. MATLAB now responds to all of the situations listed below with this one error message:

The types of invalid subscripting that yield this error are shown in this table.

Type of Subscript
Example
Complex
x(2i)
Noninteger
x(1.2)
Negative
x(-5)
Zero
x(0)
NaN
x(NaN)
Inf
x(Inf), x(-Inf)

The only functional change is that subscripting with noninteger values is now always treated as an error rather than a warning. In previous versions of MATLAB, this was an error only for sparse matrices.

Consistent Handling of Logical Errors

MATLAB now responds to the following types of invalid logical expressions as shown here:

Empty Array in Comparisons.   When you use an empty array in an equal or not equal comparison statement, MATLAB now returns an empty array as the result. In previous versions, MATLAB returned zero and displayed a warning.

For example, this statement now returns an empty array:

The previous return value was a vestige of much older MATLAB behavior. The new return value is now consistent with all other binary operations involving empty arrays. For example, [] + 5 yields [].

Operations That Are Now Considered Invalid

The following operations now return an error or warning.

Passing Complex to if or while.   Passing a complex value to if or while now returns an error:

Previously, the imaginary part was ignored unless the argument was sparse.

Passing NaN to if or while.   Passing NaN to if or while now returns an error:

Previously, this generated an error unless the NaN had the logical attribute.

Passing Complex to logical.   Passing a complex argument to the logical function or assigning a complex value to a logical variable returns an error:

This has always been an error.

Passing NaN to logical.   Passing a NaN argument to the logical function or assigning NaN to a logical variable now returns an error:

Previously, this assigned a the value NaN with a logical attribute.

Passing Complex to and, or, not.   Passing a complex argument to the and, or, or not functions now returns an error:

Previously, this assigned a the value zero.

Passing NaN to and, or, not.   Passing NaN to the and, or, or not functions now returns an error:

Previously, this assigned a the value zero.

Assigning Nonlogical Values to logical.   Passing incompatible arguments to the logical function or assigning them to a logical variable now generates a warning. Note in the example below that the value assigned to the logical array (100) is converted by MATLAB to logical 1.

Previously, this resulted in no warning and assigned 100 to a(2,3).


  Mathematics Upgrade Issues Graphics Upgrade Issues