필터 지우기
필터 지우기

Build and export tables using "struct2table" function

조회 수: 3 (최근 30일)
David Stevens
David Stevens 2015년 8월 12일
편집: David Stevens 2015년 8월 12일
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개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by