Skip to content

squeeze

Remove singleton dimensions.

B = squeeze(A)

Returns A with all dimensions of size 1 removed. A 2D matrix is unaffected (singleton dims must be in dimension 3 or higher). Useful after reductions that produce array-shaped output where you want a vector.

A = ones(2, 1, 3, 1);
size(squeeze(A)) % [2 3]
B = sum(magic(4), 2); % 4×1 column
size(squeeze(B)) % [4 1] (no change — 2D)
  • reshape — Reshape an array without changing its data.
  • permute — Rearrange dimensions of an N-D array.