Accelerating the pace of engineering and science

• Trials

# squeeze

Remove singleton dimensions

B = squeeze(A)

## Description

B = squeeze(A) returns an array B with the same elements as A, but with all singleton dimensions removed. A singleton dimension is any dimension for which size(A,dim) = 1. Two-dimensional arrays are unaffected by squeeze; if A is a row or column vector or a scalar (1-by-1) value, then B = A.

## Examples

Consider the 2-by-1-by-3 array Y = rand(2,1,3). This array has a singleton column dimension — that is, there's only one column per page.

```Y =

Y(:,:,1) =      Y(:,:,2) =
0.5194          0.0346
0.8310          0.0535

Y(:,:,3) =
0.5297
0.6711```

The command Z = squeeze(Y) yields a 2-by-3 matrix:

```Z =
0.5194    0.0346    0.5297
0.8310    0.0535    0.6711```

Consider the 1-by-1-by-5 array mat=repmat(1,[1,1,5]). This array has only one scalar value per page.

```mat =

mat(:,:,1) =		mat(:,:,2) =

1							 1

mat(:,:,3) =   mat(:,:,4) =

1							 1

mat(:,:,5) =

1
```

The command squeeze(mat) yields a 5-by-1 matrix:

```squeeze(mat)

ans =

1
1
1
1
1

size(squeeze(mat))

ans =

5     1
```