I have a 1x1 Matlab struct with 15 fields
results =
RAR_no_compartments_2_0: [1x1 struct]
RAR_no_compartments_2_1: [1x1 struct]
RAR_no_compartments_2_10: [1x1 struct]
RAR_no_compartments_2_11: [1x1 struct]
RAR_no_compartments_2_12: [1x1 struct]
RAR_no_compartments_2_13: [1x1 struct]
RAR_no_compartments_2_14: [1x1 struct]
RAR_no_compartments_2_2: [1x1 struct]
RAR_no_compartments_2_3: [1x1 struct]
RAR_no_compartments_2_4: [1x1 struct]
RAR_no_compartments_2_5: [1x1 struct]
RAR_no_compartments_2_6: [1x1 struct]
RAR_no_compartments_2_7: [1x1 struct]
RAR_no_compartments_2_8: [1x1 struct]
RAR_no_compartments_2_9: [1x1 struct]
I'm trying to cycle through each of these in a for
loop:
model_names=fieldnames(results); %get the names of each sub-struct
fieldname_dims=size(fieldnames(results)); %get dimensions of each struct
for i=1:fieldname_dims(1), %iterate over number of substructs
name=model_names(i) %get the model name
results.(name) %access the substruct
end
However Matlab returns the following error:
Argument to dynamic structure reference must evaluate to a valid field name.
Could somebody please explain to me why this is an invalid field name?