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.

3 Basic Program Components<br />

Comma-Separated Lists<br />

Typing in a series of numbers separated by commas gives you what is called a<br />

comma-separated list. <strong>MATLAB</strong> returns each value individually:<br />

1, 2, 3<br />

ans =<br />

1<br />

ans =<br />

2<br />

ans =<br />

3<br />

Such a list, by itself, is not very useful. But when used with large and<br />

more complex data structures like <strong>MATLAB</strong> structures and cell arrays, the<br />

comma-separated list can enable you to simplify your <strong>MATLAB</strong> code.<br />

This section covers<br />

• “Generating a Comma-Separated List” on page 3-80<br />

• “Assigning Output from a Comma-Separated List” on page 3-82<br />

• “Assigning to a Comma-Separated List” on page 3-83<br />

• “How to Use the Comma-Separated Lists” on page 3-84<br />

• “Fast Fourier Transform Example” on page 3-86<br />

Generating a Comma-Separated List<br />

This section describes how to generate a comma-separated list from either a<br />

cell array or a <strong>MATLAB</strong> structure.<br />

Generating a List from a Cell Array<br />

Extracting multiple elements from a cell array yields a comma-separated list.<br />

Given a 4-by-6 cell array as shown here<br />

C = cell(4, 6);<br />

for k = 1:24, C{k} = k * 2; end<br />

C<br />

3-80

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

Saved successfully!

Ooh no, something went wrong!