Main Content

cat

Concatenate symbolic arrays along specified dimension

Description

example

cat(dim,A1,...,AN) concatenates the arrays A1,...,AN along dimension dim. The remaining dimensions must be the same size.

Examples

Concatenate Two Vectors into Matrix

Create vectors A and B.

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

To concatenate A and B into a matrix, specify dimension dim as 1.

cat(1,A,B)
ans =
[ a1, a2, a3, a4]
[ b1, b2, b3, b4]

Alternatively, use the syntax [A;B].

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

Concatenate Two Vectors into One Vector

To concatenate two vectors into one vector, specify dimension dim as 2.

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

Alternatively, use the syntax [A B].

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

Concatenate Multidimensional Arrays Along Their Third Dimension

Create arrays A and B.

A = sym('a%d%d',[2 2]);
A(:,:,2) = -A
B = sym('b%d%d', [2 2]);
B(:,:,2) = -B
A(:,:,1) = 
[ a11, a12]
[ a21, a22]
A(:,:,2) = 
[ -a11, -a12]
[ -a21, -a22]
 
B(:,:,1) = 
[ b11, b12]
[ b21, b22]
B(:,:,2) = 
[ -b11, -b12]
[ -b21, -b22]
 

Concatenate A and B by specifying dimension dim as 3.

cat(3,A,B)
ans(:,:,1) = 
[ a11, a12]
[ a21, a22]
ans(:,:,2) = 
[ -a11, -a12]
[ -a21, -a22]
ans(:,:,3) = 
[ b11, b12]
[ b21, b22]
ans(:,:,4) = 
[ -b11, -b12]
[ -b21, -b22]

Input Arguments

collapse all

Dimension to concatenate arrays along, specified as a positive integer.

Input arrays, specified as symbolic variables, vectors, matrices, or multidimensional arrays.

See Also

| |

Introduced in R2010b