removevars
Delete variables from table or timetable
Syntax
Description
Examples
Remove Variable
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. Display the first three rows.
T1 = readtable('outages.csv'); head(T1,3)
ans=3×6 tableRegion 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'}
Remove the variable that is namedRegion
.
T2 = removevars(T1,'Region'); head(T2,3)
ans=3×5 tableOutageTime 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'}
Remove the fourth variable fromT2
.
T3 = removevars(T2,4); head(T3,3)
ans=3×4 tableOutageTime 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'}
Specify Multiple Variables
Remove multiple table variables using theremovevars
function. You can specify variables by name or by position.
Read data from a spreadsheet into a table.
T1 = readtable('outages.csv'); head(T1,3)
ans=3×6 tableRegion 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'}
Remove the variables named损失
andCustomers
. Specify names using a cell array of character vectors.
T2 = removevars(T1,{'Loss','Customers'}); head(T2,3)
ans=3×4 tableRegion 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'}
Remove the first and fourth variables, using a numeric array to indicate their positions inT2
.
T3 = removevars(T2,[1 4]); head(T3,3)
ans=3×2 tableOutageTime 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
Input Arguments
T1
—Input table
table|timetable
Input table, specified as a table or timetable.
vars
—Variables in input table
string array|character vector|cell array of character vectors|pattern
scalar|numeric array|逻辑阵列
Variables in the input table, specified as a string array, character vector, cell array of character vectors,pattern
scalar, numeric array, or logical array.
例子:T2 = removevars(T1,2)
removes the second table variable.
例子:T2 = removevars(T1,'Date')
removes the table variable namedDate
.
例子:T2 = removevars(T1,{'Latitude','Longitude','Elevation'})
removes the table variables namedLatitude
,Longitude
, andElevation
.
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
Usage notes and limitations:
The
vars
input argument does not support pattern expressions.
For more information, seeTall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The
vars
input argument does not support pattern expressions.
Thread-Based Environment
Run code in the background using MATLAB®backgroundPool
or accelerate code with Parallel Computing Toolbox™ThreadPool
.
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment.
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, seeRun MATLAB Functions with Distributed Arrays(Parallel Computing Toolbox).
Version History
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- 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
- 美国亲属gdom(English)