File Exchange

image thumbnail


version 1.1 (1.53 KB) by

Squish removes ALL singleton dimensions.



View License

Squish(x) will remove all singleton dimensions in x, including conversion of row vectors to column vectors.

Since singleton dimensions can confuse many operations, this function removes absolutely ALL singleton dimensions. SQUEEZE though similar, does not operate on 2D arrays which include row vectors. Thus the expected result may not always occur with SQUEEZE.

Note: This same operation can be performed with shiftdim(squeeze(x)), but squish has been timed to be faster.

For example compare the results of the following for any positive or negative n:

Comments and Ratings (1)

Jan Simon

Jan Simon (view profile)

The actual computation is short (slightly simplified and accelerated version):
dims = size(x);
y = reshape(x, [dims(dims~=1),1,1]);
H1-line existing, complete help, name of the author and date mentioned and even a comment in the 3 lines of source. The author really spent time to make his function useful and usable for the FEX members.



Modified as per Jan Simon's suggestion. It did result in a very very slight speed improvement.

MATLAB Release
MATLAB 7.9 (R2009b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today