Vertcat
Concatenate arrays vertically
描述
c = vertcat(
concatenatesA1,A2,…,一个
)A1
,A2
, … ,An
vertically.
Vertcat
is equivalent to using square brackets for vertically concatenating arrays. For example,[A; B]
is equal toVertcat(A,B)
whenA
和B
are compatible arrays.
例子
两个矩阵
创建两个矩阵并垂直串制它们,首先使用方括号符号,然后使用Vertcat
。
a = [1 2 3;4 5 6]
A =2×31 2 3 4 5 6
b = [7 8 9]
b =1×37 8 9
C =[A; B]
C =3×31 2 3 4 5 6 7 89
d = vertcat(a,b)
d =3×31 2 3 4 5 6 7 89
Two Tables
创建一个表A
with three rows and five variables.
a =表([5; 6; 5],['M';'M';'M'],[45; 41; 40],[45; 32; 34],{'NY';'CA';'嘛'},,。。。'VariableNames',{'年龄''Gender''高度''重量''Birthplace'},,。。。'RowNames',{“托马斯”'戈登''Percy'})
A=3×5 tableAge Gender Height Weight Birthplace ___ ______ ______ ______ __________ Thomas 5 M 45 45 {'NY'} Gordon 6 M 41 32 {'CA'} Percy 5 M 40 34 {'MA'}
创建一个表B
具有与A
除了订单。
b =桌子(['F';'M';'F'],[6;6;5],{'az';'NH';'co'},[31; 42; 33],[39; 43; 40],,。。。'VariableNames',{'Gender''年龄''Birthplace''重量''高度'})
B=3×5 tableGender Age Birthplace Weight Height ______ ___ __________ ______ ______ F 6 {'AZ'} 31 39 M 6 {'NH'} 42 43 F 5 {'CO'} 33 40
垂直连接表A
和B
。变量C
与变量的顺序相同A
和default row names are used for the rows fromB
。
c = vertcat(A,B)
C=6×5 tableAge Gender Height Weight Birthplace ___ ______ ______ ______ __________ Thomas 5 M 45 45 {'NY'} Gordon 6 M 41 32 {'CA'} Percy 5 M 40 34 {'MA'} Row4 6 F 39 31 {'AZ'}Row5 6 M 43 42 {'nh'} row6 5 f 40 33 {'co'}
Dates with Different Types
加入日期字符向量,字符串日期和日期列的日期。结果是DateTime列向量。
chardate ='2016-03-24';strdate =“ 2016-04-19”;t = dateTime('2016-05-10',“ inputformat','yyyy-mm-dd'); C = vertcat(chardate,strdate,t)
C =3x1日期2016年3月24日,2016年4月10日10月10日
字符串数组
Concatenate three string arrays into a single array.
A1 = [“ str1”“ str2”];a2 = [“ str3”“ str4”];a3 = ["str5"“ str6”];C = Vertcat(A1,A2,A3)
C =3x2字符串“ str1”“ str2”“ str3”“ str4”“ str5”“ str6”
Matrices in a Cell Array
创建a cell array containing two matrices. Vertically concatenate the matrices from the cell array into one matrix.
M1 = [1 2; 3 4]; M2 = [5 6; 7 8]; A1 = {M1,M2}; C = vertcat(A1{:})
C =4×21 2 3 4 5 6 7 8
Input Arguments
A
—First input
scalar|vector|matrix|多维阵列|桌子|timetable
首先输入,指定为标量,向量,矩阵,多维阵列,表格或时间表。
B
—Second input
scalar|vector|matrix|多维阵列|桌子|timetable
Second input, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.
The elements of
B
are concatenated to the end of the first input along the first dimension. The sizes of the input arguments must be compatible. For example, if the first input is a matrix of size 3-by-2, thenB
must have 2 columns.您可以连接不同类型的有效组合。有关更多信息,请参阅Valid Combinations of Unlike Classes。
A1,A2,…,一个
—输入列表
comma-separated list
输入列表,指定为逗号分隔的元素列表,以根据指定的顺序连接。
The inputs must have compatible sizes. For example, if
A1
is a row vector of lengthm, then the remaining inputs must each havem圆柱垂直连接的列。您可以连接不同类型的有效组合。有关更多信息,请参阅Valid Combinations of Unlike Classes。
算法
将空数组连接到非空数阵列时,Vertcat
omits the empty array in the output. For example,vertcat([1; 2],[])
返回列矢量[1; 2]
。
如果所有输入参数都是空的,并且具有兼容大小,则Vertcat
返回一个空数组,其大小等于输出大小,就像输入是非空的一样。例如,Vertcat(zeros(1,0),zeros(2,0))
返回一个3 x-0的空数组。如果输入尺寸不兼容,则Vertcat
返回一个0 x-0空数组。
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
用法注释和限制:
Vertical concatenation of character arrays is not supported.
When vertically concatenating two tall arrays, the result is a tall array based on a different datastore than the input tall arrays. Therefore, if you try to combine the result of the concatenation with one of the input tall arrays, the arrays are incompatible. For example, the following command results in an error, since the original tall table
T
is based on one datastore, and the output of the concatenation operation is based on another datastore:T.Var3 = [T.Var1(1); T.Var2(2:end)]
Alternatively, if you only concatenate in-memory values to a tall array, then the result of the concatenation is based on the same datastore. For example, if you replace
T.Var1(1)
在上一个带有内存标量的示例中,然后命令执行:T.Var3 = [0; T.Var2(2:end)]
有关更多信息,请参阅Tall Arrays。
C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。
Thread-Based Environment
Run code in the background using MATLAB®背景池
or accelerate code with Parallel Computing Toolbox™螺纹池
。
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment。
GPU Arrays
使用并行计算工具箱™在图形处理单元(GPU)上运行加速代码。
此功能完全支持GPU数组。万博1manbetx有关更多信息,请参阅Run MATLAB Functions on a GPU(Parallel Computing Toolbox)。
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
此功能完全支持分布式数组。万博1manbetx有关更多信息,请参阅运行具有分布式数组的MATLAB功能(Parallel Computing Toolbox)。
Version History
开放示例
You have a modified version of this example. Do you want to open this example with your edits?
matlab命令
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.
选择一个网站
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:。
您还可以从以下列表中选择一个网站:
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.
美洲
- AméricaLatina(Español)
- 加拿大(英语)
- 美国(英语)