考虑以下MATLAB结构
report.SCENARIO.CAT.GAS = YEARS(n * n double)
我想构建一个表,其中字段CAT为行,字段GAS为列,然后用YEARS填充相应的单元格。我目前正在进行如下操作:
function loopover(myStruct)
scenario = fiedlnames(myStruct)
for scenarioidx = 1:length(scenario)
scenarioname = scenario{scenarioidx};
category = fieldnames(myStruct.(scenarioname))
row = category
for categoryidx = 1:length(category)
categoryname = category{categoryidx};
gas = fieldnames(myStruct.(scenarioname).(categoryname))
col = gas
end
for gasidx = 1:length(gas)
gasname = gas{gasidx}
allData(2:end) = gas #gas name starting at the second column
allData(2:end,2) = category #category name starting at the second line
allData(row,col) = myStruct.(scenarioname).(categoryname).(gasname) #filling the cells with corresponding years
end
end
运行这个小脚本时,我收到一条错误消息
未定义的函数或变量“allData”
有谁知道为什么?或者更好,如何继续构建这样的表?
P.S。:我正在使用MATLAB R2012,因此我无法访问struct2table
或cell2table
函数!