removevars
Delete variables from table or timetable
Syntax
Description
Examples
Create a table and remove variables one at a time. You can specify variables by name or by position in the table.
Read data from a spreadsheet into a table.
T1 = readtable("outages.csv",TextType="string")
T1=1468×6 table
Region OutageTime Loss Customers RestorationTime Cause
___________ ________________ ______ __________ ________________ _________________
"SouthWest" 2002-02-01 12:18 458.98 1.8202e+06 2002-02-07 16:50 "winter storm"
"SouthEast" 2003-01-23 00:49 530.14 2.1204e+05 NaT "winter storm"
"SouthEast" 2003-02-07 21:15 289.4 1.4294e+05 2003-02-17 08:14 "winter storm"
"West" 2004-04-06 05:44 434.81 3.4037e+05 2004-04-06 06:10 "equipment fault"
"MidWest" 2002-03-16 06:18 186.44 2.1275e+05 2002-03-18 23:23 "severe storm"
"West" 2003-06-18 02:49 0 0 2003-06-18 10:54 "attack"
"West" 2004-06-20 14:39 231.29 NaN 2004-06-20 19:16 "equipment fault"
"West" 2002-06-06 19:28 311.86 NaN 2002-06-07 00:51 "equipment fault"
"NorthEast" 2003-07-16 16:23 239.93 49434 2003-07-17 01:12 "fire"
"MidWest" 2004-09-27 11:09 286.72 66104 2004-09-27 16:37 "equipment fault"
"SouthEast" 2004-09-05 17:48 73.387 36073 2004-09-05 20:46 "equipment fault"
"West" 2004-05-21 21:45 159.99 NaN 2004-05-22 04:23 "equipment fault"
"SouthEast" 2002-09-01 18:22 95.917 36759 2002-09-01 19:12 "severe storm"
"SouthEast" 2003-09-27 07:32 NaN 3.5517e+05 2003-10-04 07:02 "severe storm"
"West" 2003-11-12 06:12 254.09 9.2429e+05 2003-11-17 02:04 "winter storm"
"NorthEast" 2004-09-18 05:54 0 0 NaT "equipment fault"
⋮
Remove the variable that is named Region.
T2 = removevars(T1,"Region")T2=1468×5 table
OutageTime Loss Customers RestorationTime Cause
________________ ______ __________ ________________ _________________
2002-02-01 12:18 458.98 1.8202e+06 2002-02-07 16:50 "winter storm"
2003-01-23 00:49 530.14 2.1204e+05 NaT "winter storm"
2003-02-07 21:15 289.4 1.4294e+05 2003-02-17 08:14 "winter storm"
2004-04-06 05:44 434.81 3.4037e+05 2004-04-06 06:10 "equipment fault"
2002-03-16 06:18 186.44 2.1275e+05 2002-03-18 23:23 "severe storm"
2003-06-18 02:49 0 0 2003-06-18 10:54 "attack"
2004-06-20 14:39 231.29 NaN 2004-06-20 19:16 "equipment fault"
2002-06-06 19:28 311.86 NaN 2002-06-07 00:51 "equipment fault"
2003-07-16 16:23 239.93 49434 2003-07-17 01:12 "fire"
2004-09-27 11:09 286.72 66104 2004-09-27 16:37 "equipment fault"
2004-09-05 17:48 73.387 36073 2004-09-05 20:46 "equipment fault"
2004-05-21 21:45 159.99 NaN 2004-05-22 04:23 "equipment fault"
2002-09-01 18:22 95.917 36759 2002-09-01 19:12 "severe storm"
2003-09-27 07:32 NaN 3.5517e+05 2003-10-04 07:02 "severe storm"
2003-11-12 06:12 254.09 9.2429e+05 2003-11-17 02:04 "winter storm"
2004-09-18 05:54 0 0 NaT "equipment fault"
⋮
Remove the fourth variable from T2.
T3 = removevars(T2,4)
T3=1468×4 table
OutageTime Loss Customers Cause
________________ ______ __________ _________________
2002-02-01 12:18 458.98 1.8202e+06 "winter storm"
2003-01-23 00:49 530.14 2.1204e+05 "winter storm"
2003-02-07 21:15 289.4 1.4294e+05 "winter storm"
2004-04-06 05:44 434.81 3.4037e+05 "equipment fault"
2002-03-16 06:18 186.44 2.1275e+05 "severe storm"
2003-06-18 02:49 0 0 "attack"
2004-06-20 14:39 231.29 NaN "equipment fault"
2002-06-06 19:28 311.86 NaN "equipment fault"
2003-07-16 16:23 239.93 49434 "fire"
2004-09-27 11:09 286.72 66104 "equipment fault"
2004-09-05 17:48 73.387 36073 "equipment fault"
2004-05-21 21:45 159.99 NaN "equipment fault"
2002-09-01 18:22 95.917 36759 "severe storm"
2003-09-27 07:32 NaN 3.5517e+05 "severe storm"
2003-11-12 06:12 254.09 9.2429e+05 "winter storm"
2004-09-18 05:54 0 0 "equipment fault"
⋮
Remove multiple table variables using the removevars function. You can specify variables by name or by position.
Read data from a spreadsheet into a table.
T1 = readtable("outages.csv",TextType="string")
T1=1468×6 table
Region OutageTime Loss Customers RestorationTime Cause
___________ ________________ ______ __________ ________________ _________________
"SouthWest" 2002-02-01 12:18 458.98 1.8202e+06 2002-02-07 16:50 "winter storm"
"SouthEast" 2003-01-23 00:49 530.14 2.1204e+05 NaT "winter storm"
"SouthEast" 2003-02-07 21:15 289.4 1.4294e+05 2003-02-17 08:14 "winter storm"
"West" 2004-04-06 05:44 434.81 3.4037e+05 2004-04-06 06:10 "equipment fault"
"MidWest" 2002-03-16 06:18 186.44 2.1275e+05 2002-03-18 23:23 "severe storm"
"West" 2003-06-18 02:49 0 0 2003-06-18 10:54 "attack"
"West" 2004-06-20 14:39 231.29 NaN 2004-06-20 19:16 "equipment fault"
"West" 2002-06-06 19:28 311.86 NaN 2002-06-07 00:51 "equipment fault"
"NorthEast" 2003-07-16 16:23 239.93 49434 2003-07-17 01:12 "fire"
"MidWest" 2004-09-27 11:09 286.72 66104 2004-09-27 16:37 "equipment fault"
"SouthEast" 2004-09-05 17:48 73.387 36073 2004-09-05 20:46 "equipment fault"
"West" 2004-05-21 21:45 159.99 NaN 2004-05-22 04:23 "equipment fault"
"SouthEast" 2002-09-01 18:22 95.917 36759 2002-09-01 19:12 "severe storm"
"SouthEast" 2003-09-27 07:32 NaN 3.5517e+05 2003-10-04 07:02 "severe storm"
"West" 2003-11-12 06:12 254.09 9.2429e+05 2003-11-17 02:04 "winter storm"
"NorthEast" 2004-09-18 05:54 0 0 NaT "equipment fault"
⋮
Remove the variables named Loss and Customers.
T2 = removevars(T1,["Loss" "Customers"])
T2=1468×4 table
Region OutageTime RestorationTime Cause
___________ ________________ ________________ _________________
"SouthWest" 2002-02-01 12:18 2002-02-07 16:50 "winter storm"
"SouthEast" 2003-01-23 00:49 NaT "winter storm"
"SouthEast" 2003-02-07 21:15 2003-02-17 08:14 "winter storm"
"West" 2004-04-06 05:44 2004-04-06 06:10 "equipment fault"
"MidWest" 2002-03-16 06:18 2002-03-18 23:23 "severe storm"
"West" 2003-06-18 02:49 2003-06-18 10:54 "attack"
"West" 2004-06-20 14:39 2004-06-20 19:16 "equipment fault"
"West" 2002-06-06 19:28 2002-06-07 00:51 "equipment fault"
"NorthEast" 2003-07-16 16:23 2003-07-17 01:12 "fire"
"MidWest" 2004-09-27 11:09 2004-09-27 16:37 "equipment fault"
"SouthEast" 2004-09-05 17:48 2004-09-05 20:46 "equipment fault"
"West" 2004-05-21 21:45 2004-05-22 04:23 "equipment fault"
"SouthEast" 2002-09-01 18:22 2002-09-01 19:12 "severe storm"
"SouthEast" 2003-09-27 07:32 2003-10-04 07:02 "severe storm"
"West" 2003-11-12 06:12 2003-11-17 02:04 "winter storm"
"NorthEast" 2004-09-18 05:54 NaT "equipment fault"
⋮
Remove the first and fourth variables, using a numeric array to indicate their positions in T2.
T3 = removevars(T2,[1 4])
T3=1468×2 table
OutageTime RestorationTime
________________ ________________
2002-02-01 12:18 2002-02-07 16:50
2003-01-23 00:49 NaT
2003-02-07 21:15 2003-02-17 08:14
2004-04-06 05:44 2004-04-06 06:10
2002-03-16 06:18 2002-03-18 23:23
2003-06-18 02:49 2003-06-18 10:54
2004-06-20 14:39 2004-06-20 19:16
2002-06-06 19:28 2002-06-07 00:51
2003-07-16 16:23 2003-07-17 01:12
2004-09-27 11:09 2004-09-27 16:37
2004-09-05 17:48 2004-09-05 20:46
2004-05-21 21:45 2004-05-22 04:23
2002-09-01 18:22 2002-09-01 19:12
2003-09-27 07:32 2003-10-04 07:02
2003-11-12 06:12 2003-11-17 02:04
2004-09-18 05:54 NaT
⋮
Input Arguments
Input table, specified as a table or timetable.
Variables in the input table, specified as a string array, character
vector, cell array of character vectors, pattern scalar, numeric array, logical array, or subscript
object.
You can specify vars as a subscript object that detects
variables of a specified data type by using the vartype
function.
Example: T2 = removevars(T1,2) removes the second table
variable.
Example: T2 = removevars(T1,"Date") removes the table
variable named Date.
Example: T2 = removevars(T1,["Latitude" "Longitude"
"Elevation"]) removes the table variables named
Latitude, Longitude, and
Elevation.
Example: vars = vartype("numeric"); T =
removevars(T,vars) removes all of the numeric variables in
T.
Output Arguments
Output table without deleted variables, returned as a table or timetable.
Extended Capabilities
The
removevars function fully supports tall arrays. For more information,
see Tall Arrays.
Usage notes and limitations:
The
varsinput argument does not support pattern expressions.
Refer to the usage notes and limitations in the C/C++ Code Generation section. The same usage notes and limitations apply to GPU code generation.
The removevars function fully supports
thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
The removevars function fully supports
distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2018a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
