diff --git a/cell_array.m b/cell_array.m index eafae66..a4dee17 100644 --- a/cell_array.m +++ b/cell_array.m @@ -28,4 +28,18 @@ cs = {1+3 2}; assert(isequal(cs, {4 2})); % convert cell array to standard array -assert(isequal(cell2mat(cs), [4 2])); \ No newline at end of file +assert(isequal(cell2mat(cs), [4 2])); + +% arrayfun can output a non uniform cell array +struct_array(1).data = [1 2]; +struct_array(2).data = [1 2 3]; + +try + arrayfun(@(x) x.data, struct_array) +catch e + assert(isequal(e.identifier, 'MATLAB:arrayfun:NotAScalarOutput')); +end + +assert(isequal( ... + arrayfun(@(x) x.data, struct_array, 'UniformOutput', false), ... + {[1 2], [1 2 3]})); \ No newline at end of file diff --git a/struct_arrays.m b/struct_arrays.m index ea2a6d9..3f40232 100644 --- a/struct_arrays.m +++ b/struct_arrays.m @@ -12,9 +12,9 @@ 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')); +[patient1, patient2] = patient.name; +assert(isequal(patient1, 'John Doe')); +assert(isequal(patient1, 'John Doe')); % creates a new records 'age'; this will be created in all the other % entries; fields not specified here are set to []