Main Content

squeeze

Remove dimensions of length 1

Description

example

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

IfAis a row vector, column vector, scalar, or an array with no dimensions of length 1, thensqueezereturns the inputA.

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×21 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×11 2 3

Input Arguments

collapse all

Input array, specified as a multidimensional array.

Extended Capabilities

Version History

Introduced before R2006a