The usual way to iterate through a struct data type in MATLAB is using the fieldnames()
function as done in:
mystruct = struct('a',3,'b',5,'c',9);
fields = fieldnames(mystruct);
for i=1:numel(fields)
mystruct.(fields{i});
end
Unfortunately, this always generates cell data types, and I would like to use this kind of iteration for a Matlab Function Block in SIMULINK that does not allow cell data types for code generation reasons.
Is there a way to iterate through a structure without making use of cell data types at the same time?
In Octave there is a neat way of that explained in https://www.gnu.org/software/octave/doc/interpreter/Looping-Over-Structure-Elements.html
for [val, key] = mystruct
# do something esp. with 'key'
end
Does anybody know a similar way in MATLAB?