Extract Structure element dynamically
1 view (last 30 days)
Show older comments
Life is Wonderful
on 1 Nov 2019
Commented: Life is Wonderful
on 2 Nov 2019
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));
0 Comments
Accepted Answer
Turlough Hughes
on 1 Nov 2019
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 Comments
More Answers (1)
Fangjun Jiang
on 1 Nov 2019
%%
s.a=1:10;
s.b=rand(1,10);
EleNames=fieldnames(s);
plot(s.(EleNames{1}),s.(EleNames{2}));
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!