Main Content

addvars

将变量添加到表或时间表

Description

t2 = addvars(T1.var1,...,varNadds the variables specified byvar1,...,变华to the right of the last variable ofT1.。输入参数var1,...,变华can include arrays of any type, tables, and timetables. All input arguments must have the same number of rows.

t2 = addvars(T1.var1,...,varN那'之前'那位置将变量插入到表变量的左侧位置(see diagram). You can specify位置作为变量名,或数字或逻辑索引。

t2 = addvars(T1.var1,...,varN那'后'那位置将变量插入到表变量的右侧位置

t2 = addvars(___,'newvariablenames',纽姆姆斯renames the added variables inT2.using the names specified by纽姆姆斯。名称的数量纽姆姆斯必须与添加变量的数量相同。您可以使用此语法与先前语法的任何输入参数。

Examples

collapse all

创建一个表。然后将来自Workspace的变量添加到表中。

Load arrays from thepatients.matfile. Create a table that contains the names, ages, heights, and weights of patients. Then display the first three rows.

加载patientst1 =表(姓氏,年龄,高度,重量);头(T1,3)
ans=3×4表LastName Age Height Weight ____________ ___ ______ ______ {'Smith' } 38 71 176 {'Johnson' } 43 69 163 {'Williams'} 38 64 131

加the workspace variables,性别and吸烟者,到桌子上。

t2 = addvars(t1,性别,吸烟者);头(T2,3)
ans=3×6表姓氏年度高度重量性别吸烟_______________ ______________________________________________'mal'} false {johnson'} false {williams'} 38 64 131 {''女性'}虚假

创建一个表。Then insert variables before and after specified locations in the table.

Load arrays from thepatients.matfile. Create a table that contains the names and genders of patients. Then display the first three rows.

加载patientst1 =表(LastName,性别);头(T1,3)
ans=3×2 tableLastName Gender ____________ __________ {'Smith' } {'Male' } {'Johnson' } {'Male' } {'Williams'} {'Female'}

插入工作区变量,年龄,在表变量之前,性别。To refer to a table variable by name, specify its name as a character vector.

t2 = addvars(t1,年龄,'之前''性别');头(T2,3)
ans=3×3表姓氏年代性别____________ ___ __________ {'史密斯'} 38 {'male'} {'johnson'} 43 {'male'} {'williams'} 38 {'女'}

后面插入更多变量年龄。由于年龄是T2中的表变量,因此将其名称指定为字符向量。

t3 = addvars(t2,高度,重量,'后''Age');头(T3,3)
ans=3×5表LastName Age Height Weight Gender ____________ ___ ______ ______ __________ {'Smith' } 38 71 176 {'Male' } {'Johnson' } 43 69 163 {'Male' } {'Williams'} 38 64 131 {'Female'}

插入吸烟者after the first table variable. You can specify variables by position in the table instead of by name.

T4 = addvars(T3,吸烟者,'后',1);头(T4,3)
ans=3×6表姓氏吸烟年龄高度重量性别____________ _____________________________________'女'}

创建一个表。添加变量并在表格中给予它们新名称。

First, create a table from workspace variables.

加载patientst1 =表(姓氏,年龄,性别,吸烟者);头(T1,3)
ans=3×4表LastName Age Gender Smoker ____________ ___ __________ ______ {'Smith' } 38 {'Male' } true {'Johnson' } 43 {'Male' } false {'Williams'} 38 {'Female'} false

结合Diastolicand收缩系统进入一个带有两列的一个矩阵。命名新表变量血压

t2 = addvars(T1.那[Diastolic Systolic],'newvariablenames''BloodPressure');头(T2,3)
ans=3×5表LastName Age Gender Smoker BloodPressure ____________ ___ __________ ______ _____________ {'Smith' } 38 {'Male' } true 93 124 {'Johnson' } 43 {'Male' } false 77 109 {'Williams'} 38 {'Female'} false 83 125

Heightand重量as new table variables. Rename them英寸andPounds

t3 = addvars(t2,高度,重量,'之前''Smoker''newvariablenames'那{'英寸''磅'});头(T3,3)
ans=3×7 table吸烟者BloodPres LastName年龄性别英寸磅sure ____________ ___ __________ ______ ______ ______ _____________ {'Smith' } 38 {'Male' } 71 176 true 93 124 {'Johnson' } 43 {'Male' } 69 163 false 77 109 {'Williams'} 38 {'Female'} 64 131 false 83 125

输入参数

collapse all

输入表,指定为表或时间表。

Variables to add to the output table, specified as arrays, tables, and timetables. The variables specified byvar1,...,varNall must have the same number of rows as the input tableT1.

Example:t2 = addvars(T1.那一种)插入工作区变量一种在最后一个表变量的右侧。

Example:t2 = addvars(T1.那X那y那Z.)插入工作区变量Xy那andZ.

插入添加变量的位置,指定为字符向量,字符串标量,整数或逻辑阵列。

  • If位置is a character vector or string scalar, then it is the name of a variable in the input tableT1.

  • If位置是整数N那then it specifies theN变量in.T1.

  • If位置is a logical array, whoseNth element is1true),然后它指定了N变量in.T1.。所有其他元素位置must be0.)。

Example:t2 = addvars(T1.那纬度那'之前'那'经度')插入工作区变量纬度to the left of the table variable named经度

Example:t2 = addvars(t1,y,z,'之后','x')插入工作区变量yandZ.在表变量命名的右侧X

添加变量的名称,指定为字符向量,字符向量单元格数组或字符串数​​组。

Example:t2 = addvars(T1.那lat,lon,'NewVariableNames',{'Latitude','Longitude'})插入工作区变量latandlon并命名相应的表变量'Latitude'and'经度'

Limitations

  • Use single quotes for the input names'之前''后'那and'newvariablenames'。To avoid confusion with variable inputs, do not use double-quoted string scalars (such as"Before")for these names.

扩展能力

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

在R2018A介绍