Element-by-Element Organization
Consider a database with patient information. Each record contains data for the patient’s
name, test results, and billing amount.
These statements create an element in a structure array named patient:
patient(1).name = 'John Doe';
patient(1).billing = 127.00;
patient(1).test = [79, 75, 73; 180, 178, 177.5; 220, 210, 205];
Additional patients correspond to new elements in the structure. For example, add an
element for a second patient:
patient(2).name = 'Ann Lane';
patient(2).billing = 28.50;
patient(2).test = [68, 70, 68; 118, 118, 119; 172, 170, 169];
Element-by-element organization supports simple indexing to access data for a particular
patient. For example, find the average of the first patient’s test results, calculating by
rows (dimension 2 ) rather than by columns:
aveResultsDoe = mean(patient(1).test,2)
This code returns
aveResultsDoe =
75.6667
11 Structures