removevars
从表或时间表中删除变量
说明
示例
创建一个表并逐个删除变量。您可以通过名称或表中的位置指定变量。
将数据从电子表格读取到表中。显示前三行。
T1 = readtable('outages.csv');
head(T1,3)
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'}
删除名为 Region
的变量。
T2 = removevars(T1,'Region');
head(T2,3)
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'}
从 T2
中删除第四个变量。
T3 = removevars(T2,4); head(T3,3)
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'}
使用 removevars
函数删除多个表变量。您可以通过名称或位置指定变量。
将数据从电子表格读取到表中。
T1 = readtable('outages.csv');
head(T1,3)
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'}
删除名为 Loss
和 Customers
的变量。使用字符向量元胞数组指定名称。
T2 = removevars(T1,{'Loss','Customers'}); head(T2,3)
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'}
删除第一个和第四个变量(使用数值数组指示它们在 T2
中的位置)。
T3 = removevars(T2,[1 4]); head(T3,3)
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
输入参数
输入表,指定为表或时间表。
输入表中的变量,指定为字符串数组、字符向量、字符向量元胞数组、pattern
标量、数值数组、逻辑数组或下标对象。
您可以将 vars
指定为下标对象,通过使用 vartype
函数检测指定数据类型的变量。
示例: T2 = removevars(T1,2)
删除第二个表变量。
示例: T2 = removevars(T1,'Date')
删除名为 Date
的表变量。
示例: T2 = removevars(T1,{'Latitude','Longitude','Elevation'})
删除名为 Latitude
、Longitude
和 Elevation
的表变量。
示例: vars = vartype('numeric'); T = removevars(T,vars)
删除 T
中的所有数值变量。
扩展功能
removevars
函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
用法说明和限制:
vars
输入参量不支持模式表达式。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
此函数完全支持分布式数组。有关详细信息,请参阅使用分布式数组运行 MATLAB 函数 (Parallel Computing Toolbox)。
版本历史记录
在 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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)