Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

squeeze

Remove singleton dimensions

Syntax

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

collapse all

Create a 2-by-1-by-3 array and remove the singleton column dimension to form a 2-by-3 matrix.

y = rand(2,1,3)
z = squeeze(y)
y(:,:,1) =

    0.8147
    0.9058


y(:,:,2) =

    0.1270
    0.9134


y(:,:,3) =

    0.6324
    0.0975


z =

    0.8147    0.1270    0.6324
    0.9058    0.9134    0.0975

Create a 1-by-1-by-5 array of ones.

mat = repmat(1,[1,1,5])
mat(:,:,1) =

     1


mat(:,:,2) =

     1


mat(:,:,3) =

     1


mat(:,:,4) =

     1


mat(:,:,5) =

     1

Condense the data in the third dimension to create a 5-by-1 column vector.

squeeze(mat)
ans =

     1
     1
     1
     1
     1

More About

collapse all

Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.

Introduced before R2006a


Was this topic helpful?