Page 373 - Process Modelling and Simulation With Finite Element Methods
P. 373
360 Process Modelling and Simulation with Finite Element Methods
Cell Arrays and Structures
You could write a whole chapter about cell arrays and structures. The important
thing to note about both is that they are containers for heterogeneous mixtures of
data types - floating point numbers, complex numbers, matrices, character
strings, other cell arrays and structures. The cell array refers to each cell within
the array by an array index. Cell arrays are directly defined with braces
surrounding the list of array elements. The cell command will create an empty
shell which can be assigned individual elements or subarrays.
>> ca = { 'every', 'good', 'boy', 'does', 'find', 3+3i, [O 1; -2 21 }
ca =
Columns 1 through 6
'good' 'boy' 'does' 'find' [3.0000+ 3.0000il
I every I
Column 7
[2x2 doublel
Referencing can be done by array index, with parenthesis, returns the cell
element.
>> ca(3)
ans =
' boy
Referencing by braces and index number returns the contents of the cell element.
>> ca(3)
ans =
boy
Perhaps this is clear with regard to the matrix cell constituent,
>> ca(7)
ans =
[2x2 doublel
>> ca{7)
ans =
0 1
-2 2
Structures are referenced by fields, which are named rather than enumerated,
much as in the C programming language. The greatest utility in using a structure
as averse to a cell array is that if you choose to alter the structure, addition or
elimination of fields does not change the ordering of fields in a meaningful way.
Elimination or addition of cell array elements, however, changes the numbering
of cells or leaves "holes" in the array. The most common structure encountered
by FEMLAB users is the fem structure, which is how FEMLAB organizes the
complete set of data for its multiphysics models and their solutions. Exporting
as fern structure to the MATLAB workspace from FEMLAB produces the
following for our Benard convection model.