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.

Comma-Separated Lists<br />

C =<br />

[2] [10] [18] [26] [34] [42]<br />

[4] [12] [20] [28] [36] [44]<br />

[6] [14] [22] [30] [38] [46]<br />

[8] [16] [24] [32] [40] [48]<br />

extracting the fifth column generates the following comma-separated list:<br />

C{:, 5}<br />

ans =<br />

34<br />

ans =<br />

36<br />

ans =<br />

38<br />

ans =<br />

40<br />

Thisisthesameasexplicitlytyping<br />

C{1, 5}, C{2, 5}, C{3, 5}, C{4, 5}<br />

Generating a List from a Structure<br />

For structures, extracting a field of the structure that exists across one of its<br />

dimensions yields a comma-separated list.<br />

Start by converting the cell array used above into a 4-by-1 <strong>MATLAB</strong> structure<br />

with six fields: f1 through f6. Read field f5 for all rows and <strong>MATLAB</strong> returns<br />

a comma-separated list:<br />

S = cell2struct(C, {'f1', 'f2', 'f3', 'f4', 'f5', 'f6'}, 2);<br />

S.f5<br />

ans =<br />

34<br />

ans =<br />

36<br />

ans =<br />

38<br />

ans =<br />

3-81

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

Saved successfully!

Ooh no, something went wrong!