movevars
在表或时间表中移动变量
说明
示例
移动变量
创建一个表并逐个移动变量。您可以通过名称或表中的位置指定变量。
将数据从电子表格读取到表中。显示前三行。
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
的变量,使其位于名为 Cause
的变量之前。
T2 = movevars(T1,'Region','Before','Cause'); head(T2,3)
OutageTime Loss Customers RestorationTime Region Cause ________________ ______ __________ ________________ _____________ ________________ 2002-02-01 12:18 458.98 1.8202e+06 2002-02-07 16:50 {'SouthWest'} {'winter storm'} 2003-01-23 00:49 530.14 2.1204e+05 NaT {'SouthEast'} {'winter storm'} 2003-02-07 21:15 289.4 1.4294e+05 2003-02-17 08:14 {'SouthEast'} {'winter storm'}
移动第四个变量,使其位于第一个变量之后。
T3 = movevars(T2,4,'After',1);
head(T3,3)
OutageTime RestorationTime Loss Customers Region Cause ________________ ________________ ______ __________ _____________ ________________ 2002-02-01 12:18 2002-02-07 16:50 458.98 1.8202e+06 {'SouthWest'} {'winter storm'} 2003-01-23 00:49 NaT 530.14 2.1204e+05 {'SouthEast'} {'winter storm'} 2003-02-07 21:15 2003-02-17 08:14 289.4 1.4294e+05 {'SouthEast'} {'winter storm'}
指定多个变量
使用 movevars
函数移动多个表变量。您可以通过名称或位置指定变量。
将数据从电子表格读取到表中。
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
、Customer
和 Cause
的变量,使其位于第一个变量之前。使用字符向量元胞数组指定名称。
T2 = movevars(T1,{'Loss','Customers','Cause'},'Before',1); head(T2,3)
Loss Customers Cause Region OutageTime RestorationTime ______ __________ ________________ _____________ ________________ ________________ 458.98 1.8202e+06 {'winter storm'} {'SouthWest'} 2002-02-01 12:18 2002-02-07 16:50 530.14 2.1204e+05 {'winter storm'} {'SouthEast'} 2003-01-23 00:49 NaT 289.4 1.4294e+05 {'winter storm'} {'SouthEast'} 2003-02-07 21:15 2003-02-17 08:14
移动 T2
的前四个变量,使它们位于 RestorationTime
之后。
T3 = movevars(T2,[1:4],'After','RestorationTime'); head(T3,3)
OutageTime RestorationTime Loss Customers Cause Region ________________ ________________ ______ __________ ________________ _____________ 2002-02-01 12:18 2002-02-07 16:50 458.98 1.8202e+06 {'winter storm'} {'SouthWest'} 2003-01-23 00:49 NaT 530.14 2.1204e+05 {'winter storm'} {'SouthEast'} 2003-02-07 21:15 2003-02-17 08:14 289.4 1.4294e+05 {'winter storm'} {'SouthEast'}
输入参数
T1
— 输入表
表 | 时间表
输入表,指定为表或时间表。
vars
— 输入表中的变量
字符串数组 | 字符向量 | 字符向量元胞数组 | pattern
标量 | 数值数组 | 逻辑数组
输入表中的变量,指定为字符串数组、字符向量、字符向量元胞数组、pattern
标量、数值数组或逻辑数组。
location
— 插入所移动变量的位置
字符向量 | 字符串标量 | 整数 | 逻辑数组
要插入所移动的变量的位置,指定为字符向量、字符串标量、整数或逻辑数组。
如果
location
是字符向量或字符串标量,则它是输入表T1
中变量的名称。如果
location
是整数n
,则它指定T1
中的第n
个变量。如果
location
是逻辑数组,其第n
个元素为1
(true
),则它指定T1
中的第n
个变量。location
的所有其他元素必须为0
(false
)。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
vars
输入参数不能包含重复的变量名称。vars
输入参数不支持模式表达式。
有关详细信息,请参阅 表的代码生成 (MATLAB Coder) 和 Table Limitations for Code Generation (MATLAB Coder)。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅Run MATLAB Functions in Thread-Based Environment。
分布式数组
使用 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)