| Upgrading from MATLAB 4 to MATLAB 5.0 | Search  Help Desk |
New and Enhanced Language Functions
MATLAB 5.0 provided a large number of new language functions as well as enhancements to existing functions.Subscripting and Assignment Enhancements
In MATLAB 5.0, you can:end keyword.
A(ones([m,n])) now always returns an m-by-n array in which each element is A(1). In previous versions, the statement returned different results depending on whether A was or was not an m-by-n matrix.
In previous releases, expressions like A(2:3,4:5) = 5 resulted in an error. MATLAB 5.0 automatically "expands" the 5 to be the right size (that is, 5*ones(2,2)).
Integer Bit Manipulation Functions
Theops directory contains commands that permit bit-level operations on integers. Operations include setting and unsetting, complementing, shifting, and logical AND, OR, and XOR. Dimension Specification for Data Analysis Functions
MATLAB's basic data analysis functions now enable you to supply a second input argument. This argument specifies the dimension along which the function operates. For example, create an arrayA:
A = [3 2 4; 1 0 5; 8 2 6];To sum along the first dimension of
A, incrementing the row index, specify 1 for the dimension of operation:
sum(A,1)
ans =
12 4 15
To sum along the second dimension, incrementing the column index, specify 2 for the dimension:
sum(A,2)
ans =
9
6
16
Other functions that accept the dimension specifier include prod, cumprod, and cumsum.
Wildcards in Utility Commands
The asterisk (*) can be used as a wildcard in the clear and whos commands. This allows you, for example, to clear only variables beginning with a given character or characters, as in
clear A*
Empty Arrays
Earlier versions of MATLAB allowed for only one empty matrix, the 0-by-0 matrix denoted by[]. MATLAB 5.0 provided for matrices and arrays in which some, but not all, of the dimensions are zero. For example, 1-by-0, 10-by-0-by-20, and [3 4 0 5 2] are all possible array sizes.
The two-character sequence [] continues to denote the 0-by-0 matrix. Empty arrays of other sizes can be created with the functions zeros, ones, rand, or eye. To create a 0-by-5 matrix, for example, use
E = zeros(0,5)The basic model for empty matrices is that any operation that is defined for
m-by-n matrices, and that produces a result with a dimension that is some function of m and n, should still be allowed when m or n is zero. The size of the result should be that same function, evaluated at zero.
For example, horizontal concatenation
C = [A B]requires that
A and B have the same number of rows. So if A is m-by-n and B is m-by-p, then C is m-by-(n+p). This is still true if m or n or p is zero.
Many operations in MATLAB produce row vectors or column vectors. It is now possible for the result to be the empty row vector
r = zeros(1,0)or the empty column vector
c = zeros(0,1)Some MATLAB functions, like
sum and max, are reductions. For matrix arguments, these functions produce vector results; for vector arguments they produce scalar results. Backwards compatibility issues arise for the argument [], which in MATLAB 4 played the role of both the empty matrix and the empty vector. In MATLAB 5.0, empty inputs with these functions produce these results:
sum([]) is 0
prod([]) is 1
max([]) is []
min([]) is []