This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

squeeze

Remove dimensions of length 1

Syntax

B = squeeze(A)

Description

example

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.

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

Introduced before R2006a