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, Mfile names, MEXfile names, and MDLfile 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 hardcode the maximum identifier length as 31, you should replace these hardcoded 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 MDLfile 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
Note
Unlike most MATLAB warnings, you cannot enable this warning with the commands, warning on or warning on all . You must use the command shown above.

Warning for Identifiers Longer Than namelengthmax. If you specify an identifier that exceeds the new character limit, MATLAB generates the following warning:
<identifier> exceeds MATLAB's maximum name length of <namelengthmax> characters and has been truncated to <truncated_identifier>
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 PCode and MEXfiles. You should recompile the following files:
mxMAXNAME
.
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:
a = magic(4); b = a > 10; whos b Name Size Bytes Class b 4x4 128 double array (logical) Grand total is 16 elements using 128 bytes
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
:
a = magic(4); b = a > 10; whos b Name Size Bytes Class b 4x4 16 logical array Grand total is 16 elements using 16 bytes
Note Logical arrays in MATLAB 6.5 also require less storage space. In the example above, it took 128 bytes to store the array in MATLAB 6.1, and only 16 bytes in Version 6.5. 
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:
a = (magic(4) > 10);
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.
MATFiles. MATfiles 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.
MixedMode Arithmetic. Mixedmode 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:
b = magic(4) > 10; whos b Name Size Bytes Class b 4x4 16 logical array Grand total is 16 elements using 16 bytes b = double(b); whos b Name Size Bytes Class b 4x4 128 double array Grand total is 16 elements using 128 bytes
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:
a = logical([]); whos a Name Size Bytes Class a 0x0 0 logical array Grand total is 0 elements using 0 bytes a(1) = 1; whos a Name Size Bytes Class a 1x1 1 logical array Grand total is 1 element using 1 bytes
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:
logical(NaN) ??? Error using ==> logical NaN's cannot be converted to logicals. not(2j) ??? Error using ==> not Operands to NOT must not be complex.
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:
A = sparse([1 1 1], 1, logical([1 0 1])) ??? Error using ==> sparse Repeated indices are not supported for sparse logical matrices.
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 selfconsistent 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 0by0 empty arrays, or a 0by0 empty array with a scalar. This behavior also affects comparisons performed inside if
and while
statements.
Comparing two 0by0 empty arrays:
Comparing a 0by0 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 0by0 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 NaN
s 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 userdefined 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
:
s = sparse(eye(3)); whos s Name Size Bytes Class s 3x3 52 sparse array Grand total is 3 elements using 52 bytes
In MATLAB 6.5, sparse
becomes an attribute of a MATLAB class. The class hierarchy diagram below represents the MathWorks longrange 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:
s = sparse(eye(3)); whos s Name Size Bytes Class s 3x3 52 double array (sparse) Grand total is 3 elements using 52 bytes
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:
a = sparse(eye(3));
Note
issparse(a) and isa(a,'sparse') give different results. The former indicates that a is a sparse matrix; the latter that a is not of the sparse class.

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.
MATFiles. MATfiles 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:
s = sparse(eye(3)); s = double(s); whos s Name Size Bytes Class s 3x3 52 double array (sparse) Grand total is 3 elements using 52 bytes
Use full
instead to make the array full:
s = full(s); whos s Name Size Bytes Class s 3x3 72 double array Grand total is 9 elements using 72 bytes
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:
s = sparse(eye(3)); whos s Name Size Bytes Class s 3x3 52 double array (sparse) Grand total is 3 elements using 52 bytes s(:) = rand(3); whos s Name Size Bytes Class a 3x3 72 double array Grand total is 9 elements using 72 bytes
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.
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.
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:
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:
a = [ [] logical(0) ]; whos a Name Size Bytes Class a 1x1 8 double array Grand total is 1 element using 8 bytes
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:
Variable <variable name> has been previously used as a function name. (Type "warning off MATLAB:mir_warning_variable_used_as_function" to suppress this warning.)
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 Mfile 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 compiletime warning only. Mfiles 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. Mfiles 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 Mfile. 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:
logical
(e.g., logical(2)
):
logicals
(e.g., x = logical([1 0 1]); x(2) = 2)
:
logical
(e.g., logical(i)
):
NaN
in a logical expression (e.g., logical(NaN)
):
NaN
in an expression with and
, or
, not
(e.g., 5 & NaN
):
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
.
a = (magic(4) > 10); a(2,3) = 100 Warning: Values other than 0 or 1 converted to logical 1 a = 1 0 0 1 0 1 1 0 0 0 0 1 0 1 1 0
Previously, this resulted in no warning and assigned 100
to a(2,3)
.
Mathematics Upgrade Issues  Graphics Upgrade Issues 