Getting Started |
Structures
Structures are multidimensional MATLAB arrays with elements accessed by textual field designators. For example,
creates a scalar structure with three fields.
Like everything else in MATLAB, structures are arrays, so you can insert additional elements. In this case, each element of the array is a structure with several fields. The fields can be added one at a time,
or an entire element can be added with a single statement.
Now the structure is large enough that only a summary is printed.
There are several ways to reassemble the various fields into other MATLAB arrays. They are all based on the notation of a comma-separated list. If you type
This is a comma-separated list. Without any other punctuation, it is not very useful. It assigns the three scores, one at a time, to the default variable ans
and dutifully prints out the result of each assignment. But when you enclose the expression in square brackets,
which produces a numeric row vector containing all the scores.
just assigns the names, one at a time, to ans
. But enclosing the expression in curly braces,
creates a 1-by-3 cell array containing the three names.
calls the char
function with three arguments to create a character array from the name
fields,
Characters and Text | Scripts and Functions |