文档

加入

使用键变量将两个表或时间表组合到行中

句法

C=加入(a,b)
c =加入(a,b,name,value)
[[C,,,,IB] = join(___

Description

例子

C=加入(a,bmerges tables or timetables一个b通过匹配行,使用所有名称与名称相同的变量key variables。这钥匙值两者都必须共同一个bbut can appear in different orders.一个b可以是表,时间表或每个表格。

  • 如果一个是一个桌子,然后加入返回C作为桌子。

  • 如果一个是时间表,然后加入返回C作为时间表。

加入retains all the variables from一个并附加来自非钥匙变量的相应内容b

行标签一个b可以是关键变量。行标签是表的行名称或时间表的行时间。

例子

C=加入(a,b,,,,名称,价值将表或时间表与一个或多个指定的其他选项一起加入表或时间表名称,价值pair arguments.

例如,您可以指定要用作关键变量的变量。

例子

[[C,,,,IB] = join(___还返回索引向量IBsuch that each element ofIB标识该行b对应于该行C。您可以使用this syntax with any of the input arguments of the previous syntaxes.

Examples

全部收缩

Create a table,一个

a = table({'Janice',,,,'Jonas',,,,“哈维尔”,,,,'杰瑞',,,,'朱丽叶'}',[1; 2; 1; 2; 1],,...'variablenames',{'员工''Department'})
a =5x2 table员工部________ __________'Janice'1'Jonas'2'Javier'1'Jerry'2'Julie'1

Create a table,b,,,,和a variable in common with一个

b =表([1 2]',{'玛丽''Mona'}',...'variablenames',{'Department''Manager'})
b =2x2表部门经理_____________________________________________________________

创建一个新表格C,包含来自表的数据一个b。使用加入function to repeat and append经理来自表的数据b从表格数据一个,,,,based on the key variable,部门

C=加入(a,b)
C =5x3 table员工部门经理________ ____________________________________________________________________________________

Create a table,一个

a = table [[[5;12;23;2;6],...{'谷物';'pizza';'salmon';'饼干';'pizza'},...'variablenames',{'年龄',,,,“最喜欢的食品”},...'Rownames',{'艾米',,,,'鲍比',,,,'冬青',,,,'Harry',,,,'Sally'})
a =5x2 table年龄最爱的食品___ ____________艾米5'谷物'bobby'bobby'pizza'Holly 23'Salmon'Harry'Harry 2'Cookies'Sally 6'Pizza'

Create a table,b,,,,和one variable in common with一个

b =表({'谷物';'饼干';'pizza';'salmon';'蛋糕'},...[[110;160;140;367;243],...{'b';'D';'B-';'一个';'C-'},...'variablenames',{“最喜欢的食品”,,,,'Calories',,,,“营养果”})
b =5x3 table最喜欢的食品卡路里营养____________ ________ ________________________________________________________________________________________________________________________

创建一个新表格C,带有来自表的数据一个b。这variable in common,最喜欢的食品,,,,is used as a key variable by the加入功能。

C=加入(a,b)
C =5x4 tableAge FavoriteFood Calories NutritionGrade ___ ____________ ________ ______________ Amy 5 'cereal' 110 'B' Bobby 12 'pizza' 140 'B-' Holly 23 'salmon' 367 'A' Harry 2 'cookies' 160 'D' Sally 6 'pizza'140'b-'

TableC不包括最后一行的信息b关于'蛋糕'因为表中没有相应的条目一个

Create a table,一个

a = table [[[10;4;2;3;7],[5;4;9;6;1],[10;3;8;8;4])
a =5x3 tablevar1 var2 var3 ____ ____ ____ 10 5 10 4 4 3 2 9 8 3 6 8 7 1 4

Create a table,b,,,,givingvar2of tablebvar2从桌子一个

b= table([6;1;1;6;8],[5;4;9;6;1])
b =5x2 tablevar1 var2 ____ ____ 6 5 1 4 1 9 6 6 8 1

创建一个新表格C,包含来自表的数据一个b。利用var2in tables一个b作为关键变量加入功能。

C=加入(a,b,,,,'键',,,,'var2'
C =5x4 tablevar1_a var2 var3 var1_b ______ ____ ____ _________________________________________________________________________________ 10 6 4 4 4 4 4 4 4 4 4 4 4 4 4 3 1 3 6 8 6 8 6 7 1 4 8

加入在非键变量中添加了独特的后缀,var1,将数据与表区分开一个b

Create a new table with data from tables一个b。如果任何非键变量在两个表中都具有相同的名称,请仅保留表格一个

Create a table,一个

a =表([10; 4; 2; 3; 7],[5; 4; 9; 6; 1])
a =5x2 tableVAR1 VAR2 ____ ____ 10 5 4 4 2 9 3 6 7 1

Create a table,b,,,,givingvar2of tablebvar2从桌子一个

b= table([6;1;1;6;8],[5;4;9;6;1],[10;3;8;8;4])
b =5x3 tablevar1var2Var3 ____ ____ ____ 6 5 10 1 4 3 1 9 8 6 6 8 8 1 4

创建一个新表格C,带有来自表的数据一个b。利用var2作为关键变量加入功能并仅保留var1从桌子一个。这output tableC不包含var1来自表的数据b

C=加入(a,b,,,,'键',,,,'var2',,,,“保存”,,,,'var1'
C =5x3 tablevar1 var2 var3 ____ ____ ____ 10 5 10 4 4 3 2 9 8 3 6 8 7 1 4

Create a table,一个

a = table [[['M';'M';'F';'F';'F'],[38; 43; 38; 40; 49],...'variablenames',{'Gender''年龄'},...'Rownames',{“史密斯”'约翰逊''Williams'“琼斯”'棕色的'})
a =5x2 table性别年龄_________史密斯M 38 Johnson M 43 Williams F 38 Jones F 40 Brown F 49

Create a table,b,,,,such that the rows of一个和行bhave a one-to-one correspondence.

b= table([64;69;67;71;64],...[119; 163; 133; 176; 131],...[122 80;109 77;117 75;124 93;125 83],,...'variablenames',{'Height''重量''BloodPressure'},...'Rownames',{'棕色的''约翰逊'“琼斯”“史密斯”'Williams'})
b =5x3 table身高体重血压______ ______ __________________棕色64 119 122 80 Johnson 69 163 109 77 Jones 67 133 117 75 Smith 71 176 124 93 Williams 64 131 125 83 83

创建一个新表格C,带有来自表的数据一个b。使用行名作为键加入功能。

C=加入(a,b,,,,'键',,,,'Rownames'
C =5x5 tableGender Age Height Weight BloodPressure ______ ___ ______ ______ _____________ Smith M 38 71 176 124 93 Johnson M 43 69 163 109 77 Williams F 38 64 131 125 83 Jones F 40 67 133 117 75 Brown F 49 64 119 122 80

C一个

Create a table,一个

a = table [[[10;4;2;3;7],[5;4;9;6;1],[10;3;8;8;4])
a =5x3 tablevar1 var2 var3 ____ ____ ____ 10 5 10 4 4 3 2 9 8 3 6 8 7 1 4

Create a table,b,,,,givingvar2of tablebvar1从桌子一个,,,,but in a different order.

b =表([6; 1; 1; 1; 6; 8],[2; 3; 4; 7; 7; 10])
b =5x2 tablevar1 var2 ____ ____ 6 2 1 3 1 4 6 7 8 10

创建一个新表格C,包含来自表的数据一个b。利用var1从桌子一个var2从桌子bas key variables to the加入功能。

[c,ib] = join(a,b,'左基,,,,1,'RightKeys',,,,2)
C =5x4 tablevar1_a var2 var3 var1_b ______ ____ ____ _________________________________________________________________________________ 10 8 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 6 3 6 8 1 7 1 4 6 6
IB=5 3 1 2 4

C是水平串联一个b(ib,2)

Create two timetables that have the same row times but different variables.

流量= [0.8 0.9 0.1 0.7 0.9]';噪声= [0 1 1.5 2 2.3]';a =时间表(小时(1:5)',流量,噪音)
a =5x2时间表Time Traffic Noise ____ _______ _____ 1 hr 0.8 0 2 hr 0.9 1 3 hr 0.1 1.5 4 hr 0.7 2 5 hr 0.9 2.3
距离= [0.88 0.86 0.91 0.9 0.86]';B =时间表(小时(1:5)',距离)
b =5x1时间表Time Distance ____ ________ 1 hr 0.88 2 hr 0.86 3 hr 0.91 4 hr 0.9 5 hr 0.86

Merge the timetables.加入将行时间用作关键变量。

C=加入(a,b)
C =5x3时间表时间交通噪声距____ _______ ______ ________ 1小时0.8 0 0.88 2 HR 0.9 1 0.86 3 HR 0.1 1.5 0.91 4 HR 0.7 2 0.7 2 0.9 5 HR 0.9 2.9 2.3 0.86 0.86

创建一个时间表和一个表。

测量= [0.13 0.22 0.31 0.42 0.53 0.57 0.67 0.81 0.90 1.00]';设备= ['一个';'b';'一个';'b';'一个';'b';'一个';'b';'一个';'b'];一个= timetable(seconds(1:10)',Measurements,Device)
a =10x2 timetableTime Measurements Device ______ ____________ ______ 1 sec 0.13 A 2 sec 0.22 B 3 sec 0.31 A 4 sec 0.42 B 5 sec 0.53 A 6 sec 0.57 B 7 sec 0.67 A 8 sec 0.81 B 9 sec 0.9 A 10 sec 1 B
设备= ['一个';'b'];精度= [0.023; 0.037];B =表(设备,准确性)
b =2x2表设备精度______ ________ A 0.023 B 0.037

合并时间表和表。Device是关键变量,因为两者都一个bhave a variable with that name.C是时间表。

C=加入(a,b)
C =10x3时间表Time Measurements Device Accuracy ______ ____________ ______ ________ 1 sec 0.13 A 0.023 2 sec 0.22 B 0.037 3 sec 0.31 A 0.023 4 sec 0.42 B 0.037 5 sec 0.53 A 0.023 6 sec 0.57 B 0.037 7 sec 0.67 A 0.023 8 sec 0.81 B 0.037 9 sec0.9 A 0.023 10秒1 B 0.037

输入参数

全部收缩

输入表,指定为表,时间表或每个表格之一。对于所有关键变量,每一行一个必须完全匹配一排b

名称值对参数

指定可选的逗号分隔对名称,价值arguments.姓名是参数名称和价值是相应的值。姓名必须出现在单引号中('')。您可以指定several name and value pair arguments in any order as姓名1,Value1,...,NameN,ValueN

Example:'键',,,,2使用第二个变量一个以及第二个变量bas key variables.

全部收缩

用作键的变量,,,,specified as the comma-separated pair consisting of'键'以及一个正整数,正整数的向量,字符矢量,字符矢量的细胞阵列,逻辑向量或'Rownames'

你不能使用'键'名称值对参数与'左基'RightKeys'名称值对参数。

行标签可以是关键变量。行标签是表格的行名称或时间表的行时间。您可以指定'键'as the row labels only, as one or more variables in一个b,,,,或者as row labels and variables together.

如果you specify the value'Rownames', 然后加入使用的行名称的行一个和行名称bas keys. In this case, there must be a row inbfor every row in一个。您无法指定'Rownames'when一个是时间表。

Example:'键',,,,[[1 3]使用第一个和第三个变量一个bas key variables.

用作键的变量in一个,指定为逗号分隔对'左基以及正整数,正整数的向量,字符矢量,字符矢量的细胞阵列或逻辑向量。

You must use the'左基名称值对参数与'RightKeys'名称值对参数。'左基'RightKeys'两者都必须指定相同数量的密钥变量。加入配对键值一个bbased on their order.

行标签可以是关键变量。行标签是表格的行名称或时间表的行时间。您可以指定'左基作为行标签一个,作为一个或多个变量一个,,,,或者as row labels and variables together.

Example:“左脚犬”,1uses only the first variable in一个作为关键变量。

用作键的变量inb,指定为逗号分隔对'RightKeys'以及正整数,正整数的向量,字符矢量,字符矢量的细胞阵列或逻辑向量。

You must use the'RightKeys'名称值对参数与'左基名称值对参数。'左基'RightKeys'两者都必须指定相同数量的密钥变量。加入配对键值一个bbased on their order.

行标签可以是关键变量。行标签是表格的行名称或时间表的行时间。您可以指定'RightKeys'作为行标签b,作为一个或多个变量b,,,,或者as row labels and variables together.

Example:“ Rightkeys”,3仅在b作为关键变量。

来自一个包括C,指定为逗号分隔对'以及正整数,正整数的向量,字符矢量,字符矢量的细胞阵列或逻辑向量。

您可以使用'包括或排除关键变量以及非钥匙变量C。但是,您不能从中包含行名称或行一个,因为它们不是变量。

默认,加入includes all variables from一个

来自b包括C,指定为逗号分隔对'RightVariables'以及正整数,正整数的向量,字符矢量,字符矢量的细胞阵列或逻辑向量。

您可以使用'RightVariables'包括或排除关键变量以及非钥匙变量C。但是,您不能从中包含行名称或行b,因为它们不是变量。

默认,加入includes all variables fromb除了密钥变量。

变量加入仅保留来自一个,指定为逗号分隔对“保存”和a character vector or a cell array of character vectors that specify variable names.

关键变量出现一次C,,,,but if nonkey variables with identical names occur in一个b, 然后加入保留两个副本Cby default. Use the“保存”名称值对仅保留副本一个

Example:“饲养”,var2仅保留副本一个非钥匙变量的var2

Output Arguments

全部收缩

合并的数据一个b,作为表或时间表返回。桌子,C,在每行中包含一行一个,以相同的顺序出现。

加入createsC通过水平串联a(:,leftvars)b(ib,RightVars)。默认,左边是所有变量一个, 和RightVars都是来自b。否则,左边consists of the variables specified by the'名称值对参数,以及RightVarsconsists of the variables specified by the'RightVariables'名称值对参数。

如果一个b包含具有相同名称的非钥匙变量,加入在相应的变量名称中添加了一个唯一的后缀C,除非您指定“保存”名称值对参数。

如果一个是一个桌子,然后C也是一个桌子。如果一个是时间表,b是时间表或表格,然后C是时间表。

You can store additional metadata inC,,,,such as descriptions, variable units, variable names, and row names. For more information, see the Properties sections of桌子或者时间表

索引b,作为列向量返回。每个元素IB标识该行b对应于输出表或时间表中的该行,C

更多关于

全部收缩

密钥变量

Variable used to match and combine data between input tables一个b

核心价值

进入关键变量的输入一个

算法

加入功能首先找到一个或多个关键变量。然后,加入uses the key variables to find the row in input tableb与输入表中的每一行匹配一个,并结合这些行以在输出表中创建一行C

  • 如果有一个键值之间的一对一映射s in一个b, 然后加入sorts the data inb并将其附加到表一个

  • 如果there is a many-to-one mapping between key values in一个b, 然后加入sorts and repeats the data inb在将其附加到表格之前一个

  • 如果在关键变量中有数据b这不会映射到关键值一个, 然后加入does not include that data in the output table,C

Extended Capabilities

也可以看看

|

在R2013B中引入

这个话题有帮助吗?