diff --git a/struct_arrays.m b/struct_arrays.m index 0520ea1..ea2a6d9 100644 --- a/struct_arrays.m +++ b/struct_arrays.m @@ -10,6 +10,12 @@ patient(2).name = 'Ann Lane'; patient(2).billing = 28.50; patient(2).test = [68, 70, 68; 118, 118, 119; 172, 170, 169]; +% if the index is not specified, patient.field returns +% the fields of all its elements as multiple return values +[name1, name2] = patient.name; +assert(isequal(name1, 'John Doe')); +assert(isequal(name2, 'Ann Lane')); + % creates a new records 'age'; this will be created in all the other % entries; fields not specified here are set to [] patient(3).name = 'New Name'; @@ -21,6 +27,10 @@ customer(1).billing = 30.0; customer(1).test = []; customer(1).age = 25; +% acceess fields indirectly +field = "name"; +assert(isequal(customer(1).(field), 'Enrico')); + % concatenates patient and customer to create a new struct array v = [patient customer]; % or [patient, customer]