Considering the following MATLAB structure
report.SCENARIO.CAT.GAS = YEARS (n*n double)
I would like to build a table with the field CAT as a row and the field GAS as a column and then fill the corresponding cells with the YEARS. I am currently proceeding as follows:
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
When running this small script I just get an error message
Undefined function or variable "allData"
Does anyone know why? Or maybe better, how to proceed to build such a table?
P.S.: I am using MATLAB R2012, therefore I don´t have access to the struct2table
or cell2table
functions!