Extract Structure element dynamically

조회 수: 2 (최근 30일)
Life is Wonderful
Life is Wonderful 2019년 11월 1일
댓글: Life is Wonderful 2019년 11월 2일
I have structure whose elements name change dynamically with respect to result file name.
I need an example code which extract structure elements from structure joinedtimetable 'joinedtimetable.Properties.VariableNames'
I need them for plotting the data like
size = numel(joinedtimetable.Properties.VariableNames)
for i = 1:numel(joinedtimetable.Properties.VariableNames)
VariableNames = ExtractName(joinedtimetable.Properties.VariableNames(i);
end
subplot(size,y,i);plot(joinedtimetable.VariableNames(1),joinedtimetable.VariableNames(2));

채택된 답변

Turlough Hughes
Turlough Hughes 2019년 11월 1일
I would just convert it to a cell array which is easier to index through as you require
c=table2cell(timetable2table(joinedtimetable));
And then something like:
figure, hold on
for ii=1:size(c,2)
plot([c{:,ii}])
end
legend(joinedtimetable.Properties.VariableNames,'Interpreter','none')
How do you want to represent the non numerical data in your plots though??
  댓글 수: 6
Life is Wonderful
Life is Wonderful 2019년 11월 1일
Super thanks a ton!! Works well
Life is Wonderful
Life is Wonderful 2019년 11월 2일
Can you please help me in getting the a GUI as well ?

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2019년 11월 1일
%%
s.a=1:10;
s.b=rand(1,10);
EleNames=fieldnames(s);
plot(s.(EleNames{1}),s.(EleNames{2}));

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by