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.

3 Basic Program Components<br />

ans =<br />

10 20<br />

ans =<br />

14 12<br />

How to Use the Comma-Separated Lists<br />

Common uses for comma-separated lists are<br />

• “Constructing Arrays” on page 3-84<br />

• “Displaying Arrays” on page 3-85<br />

• “Concatenation” on page 3-85<br />

• “Function Call Arguments” on page 3-85<br />

• “Function Return Values” on page 3-86<br />

The following sections provide examples of using comma-separated lists with<br />

cell arrays. Each of these examples appliesto<strong>MATLAB</strong>structuresaswell.<br />

Constructing Arrays<br />

You can use a comma-separated list to enter a series of elements when<br />

constructing a matrix or array. Note what happens when you insert a list of<br />

elements as opposed to adding the cell itself.<br />

When you specify a list of elements with C{:, 5}, <strong>MATLAB</strong>insertsthefour<br />

individual elements:<br />

A = {'Hello', C{:, 5}, magic(4)}<br />

A =<br />

'Hello' [34] [36] [38] [40] [4x4 double]<br />

When you specify the C cell itself, <strong>MATLAB</strong> inserts the entire cell array:<br />

A = {'Hello', C, magic(4)}<br />

A =<br />

'Hello' {4x6 cell} [4x4 double]<br />

3-84

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

Saved successfully!

Ooh no, something went wrong!