0

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!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
steve
  • 511
  • 1
  • 9
  • 33
  • the variable alldata is not defined in the function, so Matlab doesn't know what it is. You have to define it before indexing it with end. – Ne_Plus_Ultra Sep 03 '15 at 12:31
  • Building tables can be done using `table`. Unfortunately the documentation doesn't mention the first release it was available is. – Adriaan Sep 03 '15 at 12:32
  • @ Adriaan - Unfortunately `table` is not available for me! – steve Sep 03 '15 at 12:34
  • @ Ne_Plus_Ultra - Thanks! I will give a try now! – steve Sep 03 '15 at 12:35
  • [This post](http://stackoverflow.com/questions/25397894/how-to-use-tables-in-older-versions-of-matlab) suggests that `table` was introduced in 2013. – beaker Sep 03 '15 at 16:22

0 Answers0