Main Content

vertcat

Concatenate symbolic arrays vertically

Description

vertcat(A1,...,AN) vertically concatenates the symbolic arrays A1,...,AN. For vectors and matrices, all inputs must have the same number of columns. For multidimensional arrays, vertcat concatenates inputs along the first dimension. The remaining dimensions must match.

example

[A1;...;AN] is a shortcut for vertcat(A1,...,AN).

example

Examples

Concatenate Two Symbolic Vectors Vertically

Concatenate the two symbolic vectors A and B to form a symbolic matrix.

A = sym('a%d',[1 4]);
B = sym('b%d',[1 4]);
vertcat(A,B)
ans =
[ a1, a2, a3, a4]
[ b1, b2, b3, b4]

Alternatively, you can use the shorthand [A;B] to concatenate A and B.

[A;B]
ans =
[ a1, a2, a3, a4]
[ b1, b2, b3, b4]

Concatenate Multiple Symbolic Arrays Vertically

Concatenate multiple symbolic arrays into one symbolic matrix.

A = sym('a%d',[1 3]);
B = sym('b%d%d',[4 3]);
C = sym('c%d%d',[2 3]);
vertcat(C,A,B)
ans =
[ c11, c12, c13]
[ c21, c22, c23]
[  a1,  a2,  a3]
[ b11, b12, b13]
[ b21, b22, b23]
[ b31, b32, b33]
[ b41, b42, b43]

Concatenate Multidimensional Arrays Vertically

Create the 3-D symbolic arrays A and B.

A = [2 4; 1 7; 3 3];
A(:,:,2) = [8 9; 4 5; 6 2];
A = sym(A)
B = [8 3; 0 2];
B(:,:,2) = [6 2; 3 3];
B = sym(B)
A(:,:,1) = 
[ 2, 4]
[ 1, 7]
[ 3, 3]
A(:,:,2) = 
[ 8, 9]
[ 4, 5]
[ 6, 2]
 
B(:,:,1) = 
[ 8, 3]
[ 0, 2]
B(:,:,2) = 
[ 6, 2]
[ 3, 3]

Use vertcat to concatenate A and B.

vertcat(A,B)
ans(:,:,1) = 
[ 2, 4]
[ 1, 7]
[ 3, 3]
[ 8, 3]
[ 0, 2]
 
ans(:,:,2) = 
[ 8, 9]
[ 4, 5]
[ 6, 2]
[ 6, 2]
[ 3, 3]

Input Arguments

collapse all

Input arrays, specified as symbolic scalar variables, matrix variables, matrix functions, or vectors, matrices, or multidimensional arrays of symbolic scalar variables.

Version History

Introduced before R2006a

expand all

See Also

|