Programming |
Replacing Lists of Variables with Cell Arrays
Cell arrays can replace comma-separated lists of MATLAB variables in
If you use the colon to index multiple cells in conjunction with the curly brace notation, MATLAB treats the contents of each cell as a separate variable. For example, assume you have a cell array T
where each cell contains a separate vector. The expression T{1:5}
is equivalent to a comma-separated list of the vectors in the first five cells of T
.
To convolve the vectors in C(1)
and C(2)
using
conv
,
Display vectors two, three, and four with
Similarly, you can create a new numeric array using the statement
You can also use content indexing on the left side of an assignment to create a new cell array where each cell represents a separate output argument:
You can display the actual eigenvectors and eigenvalues using D{1}
and D{2}
.
Note
The varargin and varargout arguments allow you to specify variable numbers of input and output arguments for MATLAB functions that you create. Both varargin and varargout are cell arrays, allowing them to hold various sizes and kinds of MATLAB data. See Passing Variable Numbers of Arguments for details.
|
Deleting Cells | Applying Functions and Operators |
© 1994-2005 The MathWorks, Inc.