# horzcat

Concatenate symbolic arrays horizontally

## Syntax

``horzcat(A1,...,AN)``
``[A1 ... AN]``

## Description

example

````horzcat(A1,...,AN)` horizontally concatenates the symbolic arrays `A1,...,AN`. For vectors and matrices, all inputs must have the same number of rows. For multidimensional arrays, `horzcat` concatenates inputs along the second dimension. The remaining dimensions must match.```

example

``[A1 ... AN]` is a shortcut for `horzcat(A1,...,AN)`.`

## Examples

### Concatenate Two Symbolic Matrices Horizontally

Create matrices `A` and `B`.

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

Concatenate `A` and `B`.

`horzcat(A,B)`
```ans = [ a11, a12, b11, b12] [ a21, a22, b21, b22]```

Alternatively, use the shortcut `[A B]`.

`[A B]`
```ans = [ a11, a12, b11, b12] [ a21, a22, b21, b22]```

### Concatenate Multiple Symbolic Arrays Horizontally

```A = sym('a%d',[3 1]); B = sym('b%d%d',[3 3]); C = sym('c%d%d',[3 2]); horzcat(C,A,B) ```
```ans = [ c11, c12, a1, b11, b12, b13] [ c21, c22, a2, b21, b22, b23] [ c31, c32, a3, b31, b32, b33]```

Alternatively, use the shortcut `[C A B]`.

`[C A B]`
```ans = [ c11, c12, a1, b11, b12, b13] [ c21, c22, a2, b21, b22, b23] [ c31, c32, a3, b31, b32, b33]```

### Concatenate Multidimensional Arrays Horizontally

Create the 3-D symbolic arrays `A` and `B`.

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

Use `horzcat` to concatenate `A` and `B`.

`horzcat(A,B)`
```ans(:,:,1) = [ a11, a12, a13, b11, b12] [ a21, a22, a23, b21, b22] ans(:,:,2) = [ -a11, -a12, -a13, -b11, -b12] [ -a21, -a22, -a23, -b21, -b22]```

Alternatively, use the shortcut `[A B]`.

`[A B]`
```ans(:,:,1) = [ a11, a12, a13, b11, b12] [ a21, a22, a23, b21, b22] ans(:,:,2) = [ -a11, -a12, -a13, -b11, -b12] [ -a21, -a22, -a23, -b21, -b22]```

## 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