squeeze
Remove singleton dimensions.
Syntax
Section titled “Syntax”B = squeeze(A)Description
Section titled “Description”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.
Examples
Section titled “Examples”A = ones(2, 1, 3, 1);size(squeeze(A)) % [2 3]B = sum(magic(4), 2); % 4×1 columnsize(squeeze(B)) % [4 1] (no change — 2D)