MATLAB Programming

MATLAB Programming MATLAB Programming

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
23.06.2015 Views

2 Data Types G = cell(1,16); for m = 1:16 G{m} = NUM(m); end Cell Arrays of Structures Use cell arrays to store groups of structures with different field architectures: cStr = cell(1,2); cStr{1}.label = '12/2/94 - 12/5/94'; cStr{1}.obs = [47 52 55 48; 17 22 35 11]; cStr{2}.xdata = [-0.03 0.41 1.98 2.12 17.11]; cStr{2}.ydata = [-3 5 18 0 9]; cStr{2}.zdata = [0.6 0.8 1 2.2 3.4]; Cell 1 of the cStr array contains a structure with two fields, one a string and the other a vector. Cell 2 contains a structure with three vector fields. When building cell arrays of structures, you must use content indexing. Similarly, you must use content indexing to obtain the contents of structures within cells. The syntax for content indexing is cellArray{index}.field For example, to access the label field of the structure in cell 1, use cStr{1}.label. 2-114

Cell Arrays Function Summary This table describes the MATLAB functions for working with cell arrays. Function cell cell2struct celldisp cellfun cellplot deal iscell num2cell Description Create a cell array. Convert a cell array into a structure array. Display cell array contents. Apply a cell function to a cell array. Display a graphical depiction of a cell array. Copy input to separate outputs. Return true for a cell array. Convert a numeric array into a cell array. 2-115

Cell Arrays<br />

Function Summary<br />

This table describes the <strong>MATLAB</strong> functions for working with cell arrays.<br />

Function<br />

cell<br />

cell2struct<br />

celldisp<br />

cellfun<br />

cellplot<br />

deal<br />

iscell<br />

num2cell<br />

Description<br />

Create a cell array.<br />

Convert a cell array into a structure array.<br />

Display cell array contents.<br />

Apply a cell function to a cell array.<br />

Display a graphical depiction of a cell array.<br />

Copy input to separate outputs.<br />

Return true for a cell array.<br />

Convert a numeric array into a cell array.<br />

2-115

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

Saved successfully!

Ooh no, something went wrong!