table.removevars
table: tblB = removevars (tblA, vars)
Remove variables from a table.
tblB = removevars (tblA, vars) removes the
variables specified by vars from the input table tblA.
vars can be any of the following types.
true the variables to be removed.
vartype object used to create a subscript that selects
variables of a specified type.
Source Code: table
removevars drops variables, selected by name or by position index.
Name = string ({'Sanchez'; 'Johnson'; 'Li'});
Age = [38; 43; 40];
Gender = categorical ({'M'; 'M'; 'F'});
Visit = datetime (2024, [1; 2; 3], [5; 6; 7]);
T = table (Name, Age, Gender, Visit)
T =
3x4 table
Name Age Gender Visit
_________ ___ ______ ___________
"Sanchez" 38 M 05-Jan-2024
"Johnson" 43 M 06-Feb-2024
"Li" 40 F 07-Mar-2024
removevars (T, 'Gender')
ans =
3x3 table
Name Age Visit
_________ ___ ___________
"Sanchez" 38 05-Jan-2024
"Johnson" 43 06-Feb-2024
"Li" 40 07-Mar-2024
Several variables can go at once, here selected by their column numbers.
removevars (T, [2, 4])
ans =
3x2 table
Name Gender
_________ ______
"Sanchez" M
"Johnson" M
"Li" F