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.

Cell Arrays<br />

For example, row 1, column 3 of cell array A contains a structure array. Use<br />

A{1,3} to select this cell, and .name to display the field name for all elements<br />

of the structure array:<br />

A{1,3}.name<br />

ans =<br />

Ann Lane<br />

ans =<br />

John Doe<br />

To display all fields of a particular element of the structure array, type<br />

A{1,3}(2)<br />

ans =<br />

name: 'John Doe'<br />

billing: 139.7200<br />

test: [4.6228 17.8260 0.3701 12.3086 14.7641]<br />

The test field of this structure array contains a 1-by-5 numeric array. Access<br />

the odd numbered elements of this field in the second element of the structure<br />

array:<br />

A{1,3}(2).test(1:2:end)<br />

ans =<br />

4.6228 0.3701 14.7641<br />

Working With Cell Arrays Within Cells<br />

The syntax for indexing into a cell array that resides in a cell of array C<br />

using content indexing is shown below. To use cell indexing on the inner cell<br />

array, replace the curly brace operator enclosing the InnerCellArrayIndes<br />

with parentheses.<br />

The syntax for content indexing is<br />

X = C{OuterCellArrayIndex}{InnerCellArrayIndex}<br />

In the example cell array created at the start of this section, A{2,2} is a cell<br />

array that resides in a cell of the outer array A. To get the third row of the<br />

inner cell array, type<br />

A{2,2}{3,:}<br />

2-105

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

Saved successfully!

Ooh no, something went wrong!