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.

2 Data Types<br />

Createa1-by-2arraywithcellsfromA(1,2) and A(1,3):<br />

X = A(1,2:3)<br />

X =<br />

[3.1416] [1x2 struct]<br />

whos X<br />

Name Size Bytes Class<br />

X 1x2 808 cell<br />

But assigning the contents of multiple cells returns a comma-separated list.<br />

In this case, you need one output variable on the left side of the assignment<br />

statement for each cell on the right side:<br />

[Y1 Y2] = A{1,2:3}<br />

Y1 =<br />

3.1416<br />

Y2 =<br />

1x2 struct array with fields:<br />

name<br />

billing<br />

test<br />

Working With Arrays Within Cells<br />

Append the parentheses operator to the cell designator A{1,1} to select<br />

specific elements of a cell. This example displays specific row and columns of<br />

the numeric array stored in cell {1,1} of A:<br />

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

ans =<br />

0.3701 12.3086 14.7641<br />

Working With Structures Within Cells<br />

Use a combination of indexing operators to access the components of a<br />

structure array that resides in a cell of a cell array. The syntax for indexing<br />

into field F of a structure array that resides in a cell of array C is<br />

X = C{CellArrayIndex}(StructArrayIndex).F(FieldArrayIndex);<br />

2-104

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

Saved successfully!

Ooh no, something went wrong!