Functions are preferred to scripts.
Nested structs are used to hold data, so that the data is labeled explicitly
rather than relying on an indexing convention.
Fields in structs can be dynamically accessed with the
someStruct.(fieldName) syntax; i.e.,
fieldName = 'someField';
someStruct.(fieldName) == someStruct.someField; % is trueand they can be iterated over in a loop like so:
fields = fieldnames(someStruct);
for i = 1:length(fields)
% Note the cell-array indexing with braces rather than parentheses
field = fields{i};
doSomethingWith(someStruct.(field));
endor, more concisely,
for field = fieldnames(someStruct)
% This line is strange but necessary because MATLAB has awful semantics
field = field{1};
doSomethingWith(someStruct.(field))
endThe second construction is more readable, but doesn't work with parfor loops.