Accessing Data in Structure Arrays
Using structure array indexing, you can access the value of any field or field element in a structure array. Likewise, you can assign a value to any field or field element. For the examples in this section, consider this structure array.
You can access subarrays by appending standard subscripts to a structure array name. For example, the line below results in a 1-by-2 structure array:
The first structure in the
mypatients array is the same as the first structure in the
To access a field of a particular structure, include a period (.) after the structure name followed by the field name:
To access elements within fields, append the appropriate indexing mechanism to the field name. That is, if the field contains an array, use array subscripting; if the field contains a cell array, use cell array subscripting, and so on:
Use the same notations to assign values to structure fields, for example,
You can extract field values for multiple structures at a time. For example, the line below creates a 1-by-3 vector containing all of the
Similarly, you can create a cell array containing the
test data for the first two structures:
|Building Structure Arrays||Using Dynamic Field Names|
© 1994-2005 The MathWorks, Inc.