Programming Previous page   Next Page

Nesting Structures

A structure field can contain another structure, or even an array of structures. Once you have created a structure, you can use the struct function or direct assignment statements to nest structures within existing structure fields.

Building Nested Structures with the struct Function

To build nested structures, you can nest calls to the struct function. For example, create a 1-by-1 structure array:

You can build nested structure arrays using direct assignment statements. These statements add a second element to the array:

Indexing Nested Structures

To index nested structures, append nested field names using dot notation. The first text string in the indexing expression identifies the structure array, and subsequent expressions access field names that contain other structures.

For example, the array A created earlier has three levels of nesting:


Previous page  Organizing Data in Structure Arrays Function Summary Next page

© 1994-2005 The MathWorks, Inc.