removevars
从表或时间表中删除变量
说明
示例
删除变量
创建一个表并逐个删除变量。您可以通过名称或表中的位置指定变量。
将数据从电子表格读取到表中。显示前三行。
T1 = readtable('outages.csv');
head(T1,3)
Region OutageTime Loss Customers RestorationTime Cause _____________ ____________________ ______ __________ ____________________ ________________ {'SouthWest'} 01-Feb-2002 12:18:00 458.98 1.8202e+06 07-Feb-2002 16:50:00 {'winter storm'} {'SouthEast'} 23-Jan-2003 00:49:00 530.14 2.1204e+05 NaT {'winter storm'} {'SouthEast'} 07-Feb-2003 21:15:00 289.4 1.4294e+05 17-Feb-2003 08:14:00 {'winter storm'}
删除名为 Region
的变量。
T2 = removevars(T1,'Region');
head(T2,3)
OutageTime Loss Customers RestorationTime Cause ____________________ ______ __________ ____________________ ________________ 01-Feb-2002 12:18:00 458.98 1.8202e+06 07-Feb-2002 16:50:00 {'winter storm'} 23-Jan-2003 00:49:00 530.14 2.1204e+05 NaT {'winter storm'} 07-Feb-2003 21:15:00 289.4 1.4294e+05 17-Feb-2003 08:14:00 {'winter storm'}
从 T2
中删除第四个变量。
T3 = removevars(T2,4); head(T3,3)
OutageTime Loss Customers Cause ____________________ ______ __________ ________________ 01-Feb-2002 12:18:00 458.98 1.8202e+06 {'winter storm'} 23-Jan-2003 00:49:00 530.14 2.1204e+05 {'winter storm'} 07-Feb-2003 21:15:00 289.4 1.4294e+05 {'winter storm'}
指定多个变量
使用 removevars
函数删除多个表变量。您可以通过名称或位置指定变量。
将数据从电子表格读取到表中。
T1 = readtable('outages.csv');
head(T1,3)
Region OutageTime Loss Customers RestorationTime Cause _____________ ____________________ ______ __________ ____________________ ________________ {'SouthWest'} 01-Feb-2002 12:18:00 458.98 1.8202e+06 07-Feb-2002 16:50:00 {'winter storm'} {'SouthEast'} 23-Jan-2003 00:49:00 530.14 2.1204e+05 NaT {'winter storm'} {'SouthEast'} 07-Feb-2003 21:15:00 289.4 1.4294e+05 17-Feb-2003 08:14:00 {'winter storm'}
删除名为 Loss
和 Customers
的变量。使用字符向量元胞数组指定名称。
T2 = removevars(T1,{'Loss','Customers'}); head(T2,3)
Region OutageTime RestorationTime Cause _____________ ____________________ ____________________ ________________ {'SouthWest'} 01-Feb-2002 12:18:00 07-Feb-2002 16:50:00 {'winter storm'} {'SouthEast'} 23-Jan-2003 00:49:00 NaT {'winter storm'} {'SouthEast'} 07-Feb-2003 21:15:00 17-Feb-2003 08:14:00 {'winter storm'}
删除第一个和第四个变量(使用数值数组指示它们在 T2
中的位置)。
T3 = removevars(T2,[1 4]); head(T3,3)
OutageTime RestorationTime ____________________ ____________________ 01-Feb-2002 12:18:00 07-Feb-2002 16:50:00 23-Jan-2003 00:49:00 NaT 07-Feb-2003 21:15:00 17-Feb-2003 08:14:00
输入参数
T1
— 输入表
表 | 时间表
输入表,指定为表或时间表。
vars
— 输入表中的变量
字符串数组 | 字符向量 | 字符向量元胞数组 | pattern
标量 | 数值数组 | 逻辑数组
输入表中的变量,指定为字符串数组、字符向量、字符向量元胞数组、pattern
标量、数值数组或逻辑数组。
示例: T2 = removevars(T1,2)
删除第二个表变量。
示例: T2 = removevars(T1,'Date')
删除名为 Date
的表变量。
示例: T2 = removevars(T1,{'Latitude','Longitude','Elevation'})
删除名为 Latitude
、Longitude
和 Elevation
的表变量。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
vars
输入参数不支持模式表达式。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2018a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
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
- United Kingdom (English)