Table 2-1: Language Changes
Function
|
Change
|
Action
|
auread, auwrite
|
New syntax.
|
Change call to use new syntax.
|
bessel
functions
|
The bessel functions no longer produce a table for vector arguments of the same orientation.
|
For example, in besselj(nu,x), specify nu as a row and x as a column to produce a table.
|
case,
otherwise,
switch
|
case, otherwise, and switch cannot be used as variable names.
|
Rename your variables.
|
dialog
|
dialog.m now creates a modal dialog.
|
Use the msgbox function instead.
|
echo
|
echo does not display multiline matrices.
|
Update code.
|
end
|
extra end statements.
|
Remove redundant end statements.
|
eps
|
eps is a function. eps = 0 no longer redefines eps for other functions (it makes a local variable called eps in the current workspace). Functions that base their tolerance on an externally defined eps won't work.
|
Change code accordingly.
|
for
|
for loop variable different after loop for empty loops. In MATLAB 4:
i = 10; for i = 1:0, %goes nowhere end i
produces i = 10. In MATLAB 5.0 it produces
i = [].
|
Protect the for loop with an isempty call:
i = 10; if ~isempty(n) for i=1:n end end i
|
global
|
Undefined globals
|
Define globals before they are used. Always put the global statement at the top of the M-file (just below the help comments). MATLAB 4 produced a link in the workspace to an uninitialized global. It shows up in whos but exist returns 0. Do not use exist to test for the first time the global has been accessed. Use isempty.
|
gradient
|
gradient no longer produces complex output.
|
Use two outputs in the 2-D case.
|
input
|
input('prompt','s') no longer outputs an initial line feed. Prompts now show up on the same line.
|
Update code accordingly if this causes a display problem. Add \n in the prompt string to force a line feed.
|
interp1
|
The old interp1 syntax (interp1(x,n)) no longer calls interpft. A warning was in place in MATLAB 4.
|
Update code accordingly.
|
|
interp1 now returns a row vector when given a row vector. It used to return a column vector.
|
Transpose the output of interp1 to produce the MATLAB 4 result when xi is a row vector.
|
|
interp1('spline') returns NaN's for out of range values.
|
Use spline directly.
|
interp2
|
The old interp2 syntax (interp2(x,y,xi)) no longer calls interp1. A warning was in place in MATLAB 4.
|
Update code accordingly.
|
interp3
|
The old interp3 syntax (interp3(z,m,n) or interp3(x,y,z,xi,yi)) no longer calls griddata. A warning was in place in MATLAB 4. interp3 is now 3-D interpolation.
|
Update code accordingly.
|
Automeshing interpolation commands
|
Interpolation automeshing has changed. griddata, interp2, interp3, interpn, and bessel* now automesh if (xi,yi) or (nu,z) are vectors of different orientations. Previously they automeshed if the vectors were different size.
|
When xi and yi are vectors of the same orientation but different lengths, change calls such as interp2(...,xi,yi) to interp2(...,xi,yi').
|
isempty
|
A == [] and A ~= [] as a check for an empty matrix produce warning messages.
|
Use isempty(A) or ~isempty(A). In a future version A == [] will produce an empty result.
|
isspace
|
isspace only returns true (1) on strings. isspace(32) is 0 (it was 1 in MATLAB 4).
|
Wrap your calls to isspace with char.
|
logical
|
Some masking operations where the mask isn't defined using a logical expression now produce an out of range index error.
|
Wrap the subscript with a call to
logical or use the logical expression A~=0 to produce MATLAB 4 behavior.
|
|
|
Boolean indexing is no longer directly supported.
|
Use logical to create the index array.
|
matlabrc
|
On the PC, MATLAB no longer stores the path in matlabrc.
|
MATLAB for PC and UNIX now uses pathdef.m.
|
max
|
max(size(v)), as a means to determine the number of elements in a vector v, fails when v is empty.
max ignores NaNs.
|
Use length(v) in place of max(size(v)).
|
min
|
min ignores NaNs.
|
Change code if necessary.
|
nargin, nargout
|
nargin and nargout are functions.
|
nargout = nargout-1 (and any similar construction) is an error. To work around this change, assign nargin to a local variable and increment that variable. Rename all occurrences of nargin to the new variable. The same holds true for all functions.
|
ones
|
A(ones(size(A))) no longer produces A.
|
This statement produces copies of the first element of A. Use A(ones(size(A))~=0) or just A to produce the MATLAB 4 behavior.
|
|
No longer accepts column vector.
|
Size vector must be a row vector with integer elements.
|
|
Functions such as ones, eye, rand, and zeros give an error if supplied with a matrix argument (such as zeros(A)).
|
Use the syntax ones(size(A)) instead.
|
polyfit
|
Second output now a structure.
|
Change code to access structure component.
|
print
|
-ocmyk is now -cmyk.
-psdefcset is now -adobecset. GIF format no longer supported. Texture mapped surfaces do not print with painter's algorithm.
|
Update code accordingly. Update code accordingly. Use alternate format. Use -zbuffer.
|
rand
|
rand('normal') and rand('uniform') no longer supported.
|
Use randn for normally distributed and rand for uniformly distributed random numbers.
|
round
|
Subscripts must be integers.
|
To reproduce MATLAB 4 behavior, wrap noninteger subscripts with round(). Strings are no longer valid subscripts (since they are not integers in the strict sense).
|
slice
|
slice no longer requires the number of columns (ncols) argument.
|
Update code accordingly.
|
sound
|
Doesn't autoscale.
|
Use soundsc.
|
strcmp strncmp
|
strcmp and strncmp now return false (0) when any argument is numeric. They used to perform an isequal.
|
Call isequal for all nonstrings you want to compare.
|
wavread, wavwrite
|
New syntax.
|
Change call to use new syntax.
|
zeros
|
No longer accepts column vector.
|
Size vector must be a row vector with integer elements.
|
Note: The following language changes do not directly apply to specific functions.
|
|
a(:) = b where a doesn't exist creates an error. This used to do the same thing as a = b(:) when a didn't exist.
|
Either initialize a or use a = b(:) instead.
|
|
Must use an explicitly empty matrix to delete elements of an array, as in a(i) = [] or
a(i,:) = []. This syntax works for all built-in data types (including cell arrays and structures).
|
Change code accordingly.
|
|
The syntax a(i) = B, when B is empty, no longer deletes elements.
|
Use a(i) = [] instead.
|
|
An attempt to delete elements of an array outside its range is no longer (incorrectly) ignored. An error is generated.
|
Change code accordingly.
|
|
Undefined variables.
|
To reproduce MATLAB 4 behavior, initialize your variable to the empty matrix ([]) or empty string ('').
|
|
Undefined outputs.
|
To reproduce MATLAB 4 behavior, initialize your outputs to the empty matrix ([]).
|
|
Indices must be integers. Strings are no longer valid indices.
|
Use a(round(ind)) to get MATLAB 4 behavior.
|
|
_,^,{, and } are now interpreted, not displayed.
|
Use \_,\^, \{, and\}.
|
|
Concatenating a string and a double truncates the double.
|
Use double to convert the string before concatenating.
|
|
Input arguments are no longer evaluated left to right.
|
Evaluate input arguments before passing them to a function.
|
|
String handling difference. In MATLAB 4
a = 32*ones(1,10); a(1:5) = 'hello' produces 'hello'. In MATLAB 5.1, it produces:
104 101 108 11 32 32 32 32 32.
|
Initialize a to be a character array or convert it after assignment.
|
|
Using inline matrix constants and continued matrix constants inside function calls:
fun(arg1,[1 2 3 3 4 5,
5 6 6])
is a syntax error.
|
Put continuation dots and semicolon after each matrix line.
|
|
|