Programming and Data Types | ![]() ![]() |
Organizing Data in Cell Arrays
Cell arrays are useful for organizing data that consists of different sizes or kinds of data. Cell arrays are better than structures for applications where:
As an example of accessing multiple fields with one statement, assume that your data consists of:
For many applications, the best data construct for this data is a structure. However, if you routinely access only the first two fields of information, then a cell array might be more convenient for indexing purposes.
This example shows how to access the first and second elements of the cell array TEST
.
This example shows how to access the first and second elements of the structure TEST
.
The varargin
and varargout
arguments are examples of the utility of cell arrays as substitutes for comma-separated lists. Create a 3-by-3 numeric
array A
.
Now apply the normest
(2-norm estimate) function to A
, and assign the function output to individual cells of B
.
All of the output values from the function are stored in separate cells of B
. B(1)
contains the norm estimate; B(2)
contains the iteration count.
![]() | Applying Functions and Operators | Nesting Cell Arrays | ![]() |