Getting Started    

Other Data Structures

This section introduces you to some other data structures in MATLAB, including

Multidimensional Arrays

Multidimensional arrays in MATLAB are arrays with more than two subscripts. They can be created by calling zeros, ones, rand, or randn with more than two arguments. For example,

creates a 3-by-4-by-5 array with a total of 3x4x5 = 60 normally distributed random elements.

A three-dimensional array might represent three-dimensional physical data, say the temperature in a room, sampled on a rectangular grid. Or, it might represent a sequence of matrices, A(k), or samples of a time-dependent matrix, A(t). In these latter cases, the (i, j)th element of the kth matrix, or the tkth matrix, is denoted by A(i,j,k).

MATLAB and Dürer's versions of the magic square of order 4 differ by an interchange of two columns. Many different magic squares can be generated by interchanging columns. The statement

generates the 4! = 24 permutations of 1:4. The kth permutation is the row vector, p(k,:). Then

stores the sequence of 24 magic squares in a three-dimensional array, M. The size of M is

It turns out that the third matrix in the sequence is Dürer's.

The statement

computes sums by varying the dth subscript. So

is a 1-by-4-by-24 array containing 24 copies of the row vector

and

is a 4-by-1-by-24 array containing 24 copies of the column vector

Finally,

adds the 24 matrices in the sequence. The result has size 4-by-4-by-1, so it looks like a 4-by-4 array.


  break Cell Arrays