Reputation: 1492
For Example we have such a table as input
>> TmpCell{1}
ans =
starttime endtime
__________ __________
7.3609e+05 7.3609e+05
7.3609e+05 7.3609e+05
7.3609e+05 7.3609e+05
7.361e+05 7.361e+05
7.361e+05 7.361e+05
7.361e+05 7.361e+05
7.361e+05 7.361e+05
7.361e+05 7.361e+05
7.361e+05 7.361e+05
7.361e+05 7.361e+05
If I want to extract data from the table its simple that I use table2array()
but I have this problem that I also have to read the table varible name as a string which is 'starttime' and 'endtime' assuming the variablenames of table I take as an input are not the same for all the tables I have to read , how can I extract that ?
Upvotes: 0
Views: 3585
Reputation: 65430
You can access this via the Properties.VariableNames
property of the table
object which will return a cell array of strings representing the variable names.
t = table(rand(4,1), rand(4,1), rand4, 1), 'VariableNames', {'a', 'b', 'c'});
a b c
_______ _______ _______
0.17587 0.34112 0.24285
0.72176 0.60739 0.91742
0.47349 0.19175 0.26906
0.15272 0.73843 0.7655
t.Properties.VariableNames
% 'a' 'b' 'c'
Upvotes: 3