Build and export tables using "struct2table" function
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dears,
I would like to build a table in "ascii" format, using the "struct2table" function. When printed into a cell my structure as the following characteristics:
report.COUNTRY.SOURCE.SCENARIO.CATEGORY.ENTITY = YEAR YEAR
Therefore in order to use the "struct2table" function I wrote a script that loops over field names as follow:
function comboloop = loopover(myStruct)
country=fieldnames(myStruct);
for countryidx=1:length(country)
countryname=country{countryidx};
source=fieldnames(myStruct.(countryname))
for sourceidx=1:length(source)
sourcename=source{sourceidx};
scenario=fieldnames(myStruct.(countryname).(sourcename))
for scenarioidx=1:length(scenario)
scenarioname=scenario{scenarioidx};
category=fieldnames(myStruct.(countryname).(sourcename).(scenarioname))
for categoryidx=1:length(category)
categoryname=category{categoryidx};
struct2table(myStruct.(countryname).(sourcename).(scenarioname).(categoryname))
end
end
end
end
end
Then, I have two problem with the output:
- The output is printed directly on the command window, therefore how can I get an output as a table (ascii) in the workspace or outside matlab? When I use:
table=struct2table(myStruct.(countryname).(sourcename).(scenarioname).(categoryname))
I have the error message "too many output arguments".
- How can I append the results of the line 12 as a row header of the created output?
category=fieldnames(myStruct.(countryname).(sourcename).(scenarioname))
Any kind of helps or hints is greatly appreciated since I am struggling quiet a lot for this task! In order to run the code a minimal example of the structure is attached
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!