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 />

C{2:4}<br />

ans =<br />

1 0 1<br />

ans =<br />

1 2 3 4 5 6 7 8 9 10<br />

ans =<br />

9 8 7<br />

Similarly, you can create a new numeric array using the statement<br />

B = [C{1}; C{2}; C{4}]<br />

B =<br />

1 2 3<br />

1 0 1<br />

9 8 7<br />

You can also use content indexing on the left side of an assignment to create a<br />

new cell array where each cell represents a separate output argument:<br />

[D{1:2}] = eig(B)<br />

D =<br />

[3x3 double] [3x3 double]<br />

You can display the actual eigenvectors and eigenvalues using D{1} and D{2}.<br />

Note The varargin and varargout arguments allow you to specify variable<br />

numbers of input and output arguments for <strong>MATLAB</strong> functions that you<br />

create. Both varargin and varargout are cell arrays, allowing them to hold<br />

various sizes and kinds of <strong>MATLAB</strong> data. See “Passing Variable Numbers of<br />

Arguments” on page 4-35 in the <strong>MATLAB</strong> <strong>Programming</strong> documentation for<br />

details.<br />

Applying Functions and Operators<br />

Use indexing to apply functions and operators to the contents of cells. For<br />

example, use content indexing to call a function with the contents of a single<br />

cell as an argument:<br />

2-109

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

Saved successfully!

Ooh no, something went wrong!