主要内容

Vertcat

Concatenate arrays vertically

描述

example

c = vertcat(A,B)concatenatesBvertically to the end ofAwhenAB具有兼容的大小(尺寸的长度匹配除了第一维中除外)。

example

c = vertcat(A1,A2,…,一个)concatenatesA1,A2, … ,Anvertically.

Vertcatis equivalent to using square brackets for vertically concatenating arrays. For example,[A; B]is equal toVertcat(A,B)whenABare 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

创建一个表Awith 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

垂直连接表AB。变量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'}

加入日期字符向量,字符串日期和日期列的日期。结果是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”

创建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

全部收缩

首先输入,指定为标量,向量,矩阵,多维阵列,表格或时间表。

Second input, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.

  • The elements ofBare 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, thenBmust have 2 columns.

  • 您可以连接不同类型的有效组合。有关更多信息,请参阅Valid Combinations of Unlike Classes

输入列表,指定为逗号分隔的元素列表,以根据指定的顺序连接。

  • The inputs must have compatible sizes. For example, ifA1is a row vector of lengthm, then the remaining inputs must each havem圆柱垂直连接的列。

  • 您可以连接不同类型的有效组合。有关更多信息,请参阅Valid Combinations of Unlike Classes

算法

将空数组连接到非空数阵列时,Vertcatomits 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

C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。

Version History

在R2006a之前引入