| Upgrading from MATLAB 4 to MATLAB 5.0 | Search  Help Desk |
New Data Constructs
MATLAB 5.0 added support for these new data constructs:Multidimensional Arrays
Arrays (other than sparse matrices) are no longer restricted to two dimensions. You can create and access arrays with two or more dimensions by:zeros, ones, or rand
cat function
repmat function
zeros, ones, and rand were extended to accept more than two dimensions as arguments. To create a 3-by-4-by-5 array of ones, for example, use
A = ones(3,4,5)The new
cat function enables you to concatenate arrays along a specified dimension. For example, create two rectangular arrays A and B:
A = [1 2 3; 4 5 6]; B = [6 2 0; 9 1 3];To concatenate these along the third dimension:
C = cat(3,A,B)
C(:,:,1) =
1 2 3
4 5 6
C(:,:,2) =
6 2 0
9 1 3
You can also create an array with two or more dimensions in which every element has the same value using the repmat function. repmat accepts the value with which to fill the array, followed by a vector of dimensions for the array. For example, to create a 2-by-2-by-3-by-3 array B where every element has the value pi:
B = repmat(pi,[2 2 3 3]);You can also use
repmat to replicate or "tile" arrays in a specified configuration.Cell Arrays
Cell arrays have elements that are containers for any type of MATLAB data, including other cells. You can build cell arrays using:{}
A{2,2} = 'string')
cell functionStructures
Structures are constructs that have named fields containing any kind of data. For example, one field might contain a text string representing a name(patient.name = 'Jane Doe'), another might contain a scalar representing a billing amount (patient.billing = 127.00), and a third might hold a matrix of medical test results. You can organize these structures into arrays of data.
Create structure arrays by using individual assignment statements or the new struct function.MATLAB Objects
Object-oriented programming is now available within the MATLAB environment.Objects
The MATLAB programming language does not require the use of data types. For many applications, however, it is helpful to associate specific attributes with certain categories of data. To facilitate this, MATLAB allows you to work with objects. Objects are typed structures. A single class name identifies both the type of the structure and the name of the function that creates objects belonging to that class. Objects differ from ordinary structures in two important ways: Data hiding.. The structure fields of objects are not visible from the command line. Instead, you can access structure fields only from within a method, an M-file associated with the object class. Methods reside in class directories. Class directories have the same name as the class, but with a prepended@ symbol. For example, a class directory named @inline might contain methods for a class called inline.
Function and expression overloading. .
You can create methods that override existing M-files. If an object calls a function, MATLAB first checks to see if there is a method of that name before calling a supplied M-file of that name. You can also provide methods that are called for MATLAB operators. For objects a and b, for instance, the expression a + b calls the method plus(a,b) if it existsCharacter Arrays
Strings now take up less memory than they did in previous releases.