how to extract all columns in between two variable names (column header) of a table?
6 views (last 30 days)
Show older comments
Biswajit Datta
on 29 Mar 2021
Commented: Biswajit Datta
on 29 Mar 2021
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
T = table(Age,Smoker,Height,Weight)
I wan't to extract the columns of a table by their variable names rather than by matrix indices. For example 'Age' and 'weight' coulmns of table T can be extracted as
T(:,{'Age', 'Weight'})
But how do I extract all the columns from 'Age' to 'Weight' ? The following syntax doesn't work
T(:,{'Age':'Weight'})
Please suggest if you have a solution. Thank you.
0 Comments
Accepted Answer
Stephen23
on 29 Mar 2021
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
T = table(Age,Smoker,Height,Weight)
L = 'Age';
R = 'Weight';
[X,Y] = ismember({L,R},T.Properties.VariableNames);
T(:,Y(1):Y(2))
More Answers (0)
See Also
Categories
Find more on Tables 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!