Filter löschen
Filter löschen

how to extract all columns in between two variable names (column header) of a table?

5 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Stephen23
Stephen23 am 29 Mär. 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)
T = 5×4 table
Age Smoker Height Weight ___ ______ ______ ______ 38 true 71 176 43 false 69 163 38 true 64 131 40 false 67 133 49 true 64 119
L = 'Age';
R = 'Weight';
[X,Y] = ismember({L,R},T.Properties.VariableNames);
T(:,Y(1):Y(2))
ans = 5×4 table
Age Smoker Height Weight ___ ______ ______ ______ 38 true 71 176 43 false 69 163 38 true 64 131 40 false 67 133 49 true 64 119

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by