Main Content

squeeze

Remove dimensions of length 1

Description

B = squeeze(A) returns an array with the same elements as the input array A, but with dimensions of length 1 removed. For example, if A is a 3-by-1-by-1-by-2 array, then squeeze(A) returns a 3-by-2 matrix.

If A is a row vector, column vector, scalar, or an array with no dimensions of length 1, then squeeze returns the input A.

example

Examples

collapse all

Create a 2-by-1-by-2 array and remove the dimension of length 1, resulting in a 2-by-2 matrix.

A = zeros(2,1,2);
A(:,:,1) = [1 2]';
A(:,:,2) = [3 4]'
A = 
A(:,:,1) =

     1
     2


A(:,:,2) =

     3
     4

B = squeeze(A)
B = 2×2

     1     3
     2     4

Create a 1-by-1-by-3 array and remove the dimensions of length 1, resulting in a 3-by-1 column vector.

A = zeros(1,1,3);
A(:,:,1:3) = [1 2 3]
A = 
A(:,:,1) =

     1


A(:,:,2) =

     2


A(:,:,3) =

     3

B = squeeze(A)
B = 3×1

     1
     2
     3

Input Arguments

collapse all

Input array, specified as a multidimensional array.

Extended Capabilities

Version History

Introduced before R2006a