MATLAB Programming
MATLAB Programming MATLAB Programming
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
- Page 164 and 165: 2 Data Types Function Summary MATLA
- Page 166 and 167: 2 Data Types Functions to Determine
- Page 168 and 169: 2 Data Types Date Strings There are
- Page 170 and 171: 2 Data Types • The day field is a
- Page 172 and 173: 2 Data Types datestr(d) ans = 01-Ma
- Page 174 and 175: 2 Data Types Utility Functions (Con
- Page 176 and 177: 2 Data Types • “Applying Functi
- Page 178 and 179: 2 Data Types where the arguments ar
- Page 180 and 181: 2 Data Types You can access subarra
- Page 182 and 183: 2 Data Types Dynamic Field Names Ex
- Page 184 and 185: 2 Data Types Deleting Fields from S
- Page 186 and 187: 2 Data Types plot(mercury, 'b') plo
- Page 188 and 189: 2 Data Types There are at least two
- Page 190 and 191: 2 Data Types Element-by-element org
- Page 192 and 193: 2 Data Types Nesting Structures A s
- Page 194 and 195: 2 Data Types Cell Arrays A cell arr
- Page 196 and 197: 2 Data Types Operation Syntax Descr
- Page 198 and 199: 2 Data Types 3-by-3 Cell Array Note
- Page 200 and 201: 2 Data Types C5 = 'Jan' 'Feb' 'Mar'
- Page 202 and 203: 2 Data Types of an array without re
- Page 204 and 205: 2 Data Types Createa1-by-2arraywith
- Page 206 and 207: 2 Data Types ans = 7 ans = 2 ans =
- Page 208 and 209: 2 Data Types 3 4 B = reshape(A, 6,
- Page 210 and 211: 2 Data Types A{1,1} = [1 2; 3 4]; A
- Page 212 and 213: 2 Data Types [5x5 double] {2x2 cell
- Page 216 and 217: 2 Data Types Function Handles A fun
- Page 218 and 219: 2 Data Types MATLAB Classes All MAT
- Page 220 and 221: 2 Data Types 2-120
- Page 222 and 223: 3 Basic Program Components Symbol R
- Page 224 and 225: 3 Basic Program Components Note If
- Page 226 and 227: 3 Basic Program Components Another
- Page 228 and 229: 3 Basic Program Components Verifyin
- Page 230 and 231: 3 Basic Program Components function
- Page 232 and 233: 3 Basic Program Components Evaluati
- Page 234 and 235: 3 Basic Program Components Keywords
- Page 236 and 237: 3 Basic Program Components Hereares
- Page 238 and 239: 3 Basic Program Components Operator
- Page 240 and 241: 3 Basic Program Components To test
- Page 242 and 243: 3 Basic Program Components Function
- Page 244 and 245: 3 Basic Program Components 5 11 10
- Page 246 and 247: 3 Basic Program Components Advantag
- Page 248 and 249: 3 Basic Program Components MATLAB E
- Page 250 and 251: 3 Basic Program Components This M-f
- Page 252 and 253: 3 Basic Program Components • “S
- Page 254 and 255: 3 Basic Program Components Operator
- Page 256 and 257: 3 Basic Program Components Word and
- Page 258 and 259: 3 Basic Program Components There ar
- Page 260 and 261: 3 Basic Program Components regexp(p
- Page 262 and 263: 3 Basic Program Components s = e =
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