23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1 Data Structures<br />

As you add dimensions to an array, you also add subscripts. A four-dimensional<br />

array, for example, has four subscripts. The first two reference a row-column<br />

pair; the second two access the third and fourth dimensions of data.<br />

Note The general multidimensional array functions reside in the datatypes<br />

directory.<br />

Creating Multidimensional Arrays<br />

You can use the same techniques to create multidimensional arrays that you<br />

use for two-dimensional matrices. In addition, <strong>MATLAB</strong> provides a special<br />

concatenation function that is useful for building multidimensional arrays.<br />

This section discusses<br />

• “Generating Arrays Using Indexing” on page 1-54<br />

• “Extending Multidimensional Arrays” on page 1-55<br />

• “Generating Arrays Using <strong>MATLAB</strong> Functions” on page 1-56<br />

• “Building Multidimensional Arrays with the cat Function” on page 1-56<br />

Generating Arrays Using Indexing<br />

One way to create a multidimensional array is to create a two-dimensional<br />

array and extend it. For example, begin with a simple two-dimensional array<br />

A.<br />

A = [5 7 8; 0 1 9; 4 3 6];<br />

A is a 3-by-3 array, that is, its row dimension is 3 and its column dimension<br />

is 3. To add a third dimension to A,<br />

A(:,:,2) = [1 0 4; 3 5 6; 9 8 7]<br />

<strong>MATLAB</strong> responds with<br />

A(:,:,1) =<br />

5 7 8<br />

0 1 9<br />

1-54

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!