call a variable in a timetable from a cell matrix

I have a loop with the column/variable names of a timetable need to be called in a loop
for 1 = 1:10
a(:,i) = Timetable.VariableNamesMatrix{i}
end
I bolded the part im having an issue with. How can I call a string from a cell array and use it in this fashion so that for example
VariableNamesMatrix{1} = Var1
and the code would enact the part in the loop as Tiimetable.Var1 when i = 1;

 Accepted Answer

for 1 = 1:10
a(:,i) = Timetable.(VariableNamesMatrix{i});
end
But you should consider just using
a = table2array(Timetable, VariableNamesMatrix);

1 Comment

Thanks! for both answers def solved this issue. I will use the table2array(). I appreciate the quick response!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2021b

Tags

Asked:

on 14 Jan 2022

Commented:

on 14 Jan 2022

Community Treasure Hunt

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

Start Hunting!