23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Multidimensional Arrays<br />

You can use vectors as array subscripts. In this case, each vector element must<br />

be a valid subscript, that is, within the bounds defined by the dimensions of<br />

the array. To access elements (2,1), (2,3), and(2,4) on page 3 of nddata,<br />

use<br />

nddata(2,[1 3 4],3);<br />

The Colon and Multidimensional Array Indexing<br />

The <strong>MATLAB</strong> colon indexing extends to multidimensional arrays. For<br />

example, to access the entire third column on page 2 of nddata, use<br />

nddata(:,3,2).<br />

The colon operator is also useful for accessing other subsets of data. For<br />

example, nddata(2:3,2:3,1) results in a 2-by-2 array, a subset of the data on<br />

page 1 of nddata. This matrix consists of the data in rows 2 and 3, columns 2<br />

and 3, on the first page of the array.<br />

The colon operator can appear as an array subscript on both sides of an<br />

assignment statement. For example, to create a 4-by-4 array of zeros:<br />

C = zeros(4, 4)<br />

Now assign a 2-by-2 subset of array nddata to the four elements in the center<br />

of C.<br />

C(2:3,2:3) = nddata(2:3,1:2,2)<br />

Linear Indexing with Multidimensional Arrays<br />

<strong>MATLAB</strong> linear indexing also extends to multidimensional arrays. In this<br />

case, <strong>MATLAB</strong> operates on a page-by-page basis to create the storage column,<br />

again appending elements columnwise. See “Linear Indexing” on page 1-19<br />

for an introduction to this topic.<br />

1-59

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

Saved successfully!

Ooh no, something went wrong!