我有一个 1x1 Matlab 结构,有 15 个字段
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]
我正在尝试循环遍历其中的每一个for
:
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
但是 Matlab 返回以下错误:
Argument to dynamic structure reference must evaluate to a valid field name.
有人可以向我解释为什么这是一个无效的字段名称吗?