Index into Nonscalar Structure Array
Structure arrays can be nonscalar. You can create a structure array having any size, as long as each
structure in the array has the same fields.
For example, add a second structure to patients having data about a second patient. Also, assign
the original value of 127 to the billing field of the first structure. Since the array now has two
structures, you must access the first structure by indexing, as in patient(1).billing = 127.
patient(2).name = 'Ann Lane';
patient(2).billing = 28.50;
patient(2).test = [68 70 68; 118 118 119; 172 170 169];
patient(1).billing = 127
patient=1×2 struct array with fields:
name
billing
test
As a result, patient is a 1-by-2 structure array with contents shown in the diagram.
11 Structures
11-4
Précédent

- 522/1450

Suivant