Main Content

Horzcat

水平的串联阵列

描述

例子

C= horzcat(一个,,,,b连接bhorizontally to the end of一个什么时候一个andbhave compatible sizes (the lengths of the dimensions match except in the second dimension).

例子

C= horzcat(A1,,,,一个2,…,An连接A1,,,,A2,…,,一个horizontally.

Horzcat相当于使用方括号用于水平串联阵列。例如,[A,B]or[A B]等于Horzcat(A,B)什么时候一个andb是兼容阵列。

例子

全部收缩

Create two matrices and concatenate them horizontally, first by using square bracket notation, and then by usingHorzcat

a =[1 2; 3 4]
a =2×21 2 3 4
b = [4 5 6;7 8 9]
b=2×34 5 6 7 8 9
c = [a,b]
C=2×51 2 4 5 6 3 4 7 8 9
d = horzcat(a,b)
D =2×51 2 4 5 6 3 4 7 8 9

Create a table一个有三行和两个变量。

a =table([5;6;5],['M';'M';'M'],...'variablenames',,,,{'Age''性别'},,...'Rownames',,,,{'Thomas''Gordon'“珀西”})
a =3×2桌年龄性别___ ______托马斯5 m戈登6 m珀西5 m

Create a tableb有三行和三个变量。

b =表([45; 41; 40],[45; 32; 34],{'ny';'ca';'MA'},,...'variablenames',,,,{'Height'“重量”'出生地'},,...'Rownames',,,,{“珀西”'Gordon''Thomas'})
b =3×3桌身高体重出生地______ ______ __________珀西45 45 {'ny'}戈登41 32 {'ca'} thomas 40 34 {'ma'}

水平连接一个andb。行的顺序C匹配订单一个

C= horzcat(A,B)
C =3×5桌Age Gender Height Weight Birthplace ___ ______ ______ ______ __________ Thomas 5 M 40 34 {'MA'} Gordon 6 M 41 32 {'CA'} Percy 5 M 45 45 {'NY'}

加入日期字符向量,字符串日期和日期日期的日期。结果是DateTime行向量。

木薯='2016-03-24';strdate ="2016-04-19";t = datetime('2016-05-10',,,,'InputFormat',,,,'yyyy-MM-dd');c = horzcat(Chardate,strdate,t)
C=1x3 DateTime24-Mar-2016 19-Apr-2016 10-May-2016

将三个字符串阵列加入到一个数组中。

a1 = ["str1";"str2"]; A2 = ["str3";"str4"]; A3 = [“ str5”;“ str6”]; C = horzcat(A1,A2,A3)
C=2x3字符串“ str1”“ str3”“ str5”“ str2”“ str4”“ str6”

Create a cell array containing two matrices. Horizontally concatenate the matrices from the cell array into one matrix.

m1 = [1 2;3 4];m2 = [5 6 7;8 9 10];a1 = {m1,m2};c = horzcat(a1 {:})
C=2×51 2 5 6 7 3 4 8 9 10

输入参数

全部收缩

第一输入,,,,specified as a scalar, vector, matrix, multidimensional array, table, or timetable.

第二输入,指定为标量,矢量,矩阵,多维阵列,表格或时间表。

  • 元素bare concatenated to the end of the first input along the second 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必须有3行。

  • 所有表输入都必须具有唯一的变量名称。在场时,除顺序外,行名称必须相同。

  • 所有时间表输入都必须具有相同的行时间,并且所有列必须具有不同的名称。

  • 您可以连接不同类型的有效组合。有关更多信息,请参阅与课程不同的有效组合

List of inputs, specified as a comma-separated list of elements to concatenate in the order they are specified.

  • 输入必须具有兼容大小。例如,如果A1是长度的列矢量m,然后其余的输入必须每个输入m排成串联的行。

  • 所有表输入都必须具有唯一的变量名称。在场时,除顺序外,行名称必须相同。

  • 所有时间表输入都必须具有相同的行时间,并且所有列必须具有不同的名称。

  • 您可以连接不同类型的有效组合。有关更多信息,请参阅与课程不同的有效组合

Tips

  • 要通过水平串联字符串,字符矢量或字符向量的单元格数来构造文本,请使用Strcat功能。

  • To construct a single piece of delimited text from a cell array of character vectors or a string array, use theStr Join功能。

一个lgorithms

For table inputs,Horzcat在存在时通过匹配行名称或匹配表位置来连接。Horzcatassigns values for the描述andUserDataproperties of the output using the first nonempty values of the corresponding properties of the input.

When concatenating an empty array to a nonempty array,Horzcat省略输出中的空数组。例如,horzcat([1 2],[])返回行矢量[1 2]

如果所有的输入参数s are empty and have compatible sizes, thenHorzcatreturns an empty array whose size is equal to the output size as when the inputs are nonempty. For example,horzcat(零(0,1),零(0,2))返回一个0 x-3空数组。如果输入尺寸不兼容,则Horzcatreturns a 0-by-0 empty array.

扩展功能

C/C ++代码生成
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a