Each patient record in the array is a structure of class struct. An array of structures is sometimes
referred to as a struct array. However, the terms struct array and structure array mean the same
thing. Like other MATLAB® arrays, a structure array can have any dimensions.
A structure array has the following properties:
• All structures in the array have the same number of fields.
• All structures have the same field names.
• Fields of the same name in different structures can contain different types or sizes of data.
If you add a new structure to the array without specifying all of its fields, then the unspecified fields
contain empty arrays.
patient(3).name = 'New Name';
patient(3)
ans = struct with fields:
name: 'New Name'
billing: []
test: []
To index into a structure array, use array indexing. For example, patient(2) returns the second
structure.
patient(2)
ans = struct with fields:
name: 'Ann Lane'
billing: 28.5000
test: [3x3 double]
To access a field, use array indexing and dot notation. For example, return the value of the billing
field for the second patient.
Structure Arrays
11-5
referred to as a struct array. However, the terms struct array and structure array mean the same
thing. Like other MATLAB® arrays, a structure array can have any dimensions.
A structure array has the following properties:
• All structures in the array have the same number of fields.
• All structures have the same field names.
• Fields of the same name in different structures can contain different types or sizes of data.
If you add a new structure to the array without specifying all of its fields, then the unspecified fields
contain empty arrays.
patient(3).name = 'New Name';
patient(3)
ans = struct with fields:
name: 'New Name'
billing: []
test: []
To index into a structure array, use array indexing. For example, patient(2) returns the second
structure.
patient(2)
ans = struct with fields:
name: 'Ann Lane'
billing: 28.5000
test: [3x3 double]
To access a field, use array indexing and dot notation. For example, return the value of the billing
field for the second patient.
Structure Arrays
11-5
