Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Stephen23
Stephen23 el 29 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by