필터 지우기
필터 지우기

Creating structs with variable names of read-in data parameter names

조회 수: 1 (최근 30일)
I'm reading large excel file with both headers and data values. I've attached a sample.
I have many 'Days' (Day 1, Day 2, Day 3 etc.) of data. On any given 'Day,' I may have a few 'tests' (test1, test2, test3 etc.). Within those tests I have a couple variances, like stage, or if the column contains input data or measured values.
I have several columns of data correpsoinding Day 1, Day 2 and so on. What I want is to create a struct for each 'Day' and test whose variable names are the names of the day and test number, so I could say
M = Day1.test1
or something like that. The end goal is to write a csv file for each individual test. I was thinking structs would be a good way to do that, but if someone has a better suggestion I would gladly take it. Thanks
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 11일
This is not clear, give a short example
Mark
Mark 2014년 2월 11일
편집: Mark 2014년 2월 11일
days = [ 'Day 1' 'Day 2' 'Day 3' ];
DayTestNumber = [ test1, test2, test3];
for i = 1:3
variableDay = days(i)
for j = 1:3
variableTest = DayTestNumber(j)
end
variableDay.variableTest.time = stuff
variableDay.variableTest.data = moreStuff
end
I want to write
Day1.test1
or
Day1.test3
or
Day2.test2
etc and be able to access the right data, where the 'stuff' is different for each day and test.
Also see the sample .txt I attached to get a picture of what I'm workin with.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2014년 2월 11일
Dynamic field names can get you everything except for the outer structure name, but you could toss everything into one container struct.
M = alldays.(DayField).(TestField)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by