Upgrading from MATLAB 4 to MATLAB 5.0     Search    Help Desk 

New Data Constructs

MATLAB 5.0 added support for these new data constructs:

In addition, MATLAB 5.0 featured character arrays that incorporate an improved storage method for string data.

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:

MATLAB functions like 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

The new cat function enables you to concatenate arrays along a specified dimension. For example, create two rectangular arrays A and B:

To concatenate these along the third dimension:

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:

You can also use repmat to replicate or "tile" arrays in a specified configuration.

Table 1-1: New Multidimensional Array Functions  
Function
Description
cat
Concatenate arrays.
flipdim
Flip array along specified dimension.
ndgrid
Generate arrays for multidimensional functions and interpolation.
ndims
Return number of array dimensions.
permute, ipermute
Permute the dimensions of a multidimensional array.
reshape
Change size.
shiftdim
Shift dimensions.
squeeze
Remove singleton array dimensions.
sub2ind, ind2sub
Return single index from subscripts; subscripts from linear index.

Cell Arrays

Cell arrays have elements that are containers for any type of MATLAB data, including other cells. You can build cell arrays using:

Structures

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.

Table 1-3: New Structure Functions
Function
Description
fieldnames
Return field names of structure array.
getfield
Get field of structure array.
rmfield
Remove structure fields.
setfield
Set field of structure array.
struct
Create structure array.
struct2cell
Convert structure to a cell array.

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 exists

Table 1-4: New Object-Oriented Functions
Function
Description
class
Create or return class of object.
isa
True if object is a given class.
inferiorto
Inferior class relationship.
superiorto
Superior class relationship.

Character Arrays

Strings now take up less memory than they did in previous releases.
MATLAB 4 required 64 bits per character for string data. MATLAB 5.0 reduced the memory required to only 16 bits per character.

Table 1-5: New Character String Functions  
Function
Description
base2dec
Convert base B to decimal number.
bin2dec
Convert binary to decimal number.
char
Convert numeric values to string.
dec2base
Convert decimal number to base.
dec2bin
Convert decimal to binary number.
mat2str
Convert a matrix into a string.
strcat
String concatenation.
strmatch
Find possible matches for a string.
strncmp
Compare the first n characters of two strings.
strvcat
Vertical concatenation of strings.



[ Previous | Help Desk | Next ]