Code covered by the BSD License  

Highlights from
Squish

5.0

5.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.53 KB File ID: #11945

Squish

by Mirko Hrovat

 

11 Aug 2006 (Updated 27 Feb 2010)

Squish removes ALL singleton dimensions.

| Watch this File

File Information
Description

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:
size(squeeze(shiftdim([1:3]',n)))
size(squish(shiftdim([1:3]',n)))

MATLAB release MATLAB 7.9 (2009b)
Other requirements Should work on all platforms and all versions that support "reshape".
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
21 Oct 2009 Jan Simon

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.

Please login to add a comment or rating.
Updates
17 Aug 2006

Function has been modified to use logical indexing instead of "find".

27 Feb 2010

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

Tag Activity for this File
Tag Applied By Date/Time
matrices Mirko Hrovat 22 Oct 2008 08:34:49
squeeze Mirko Hrovat 22 Oct 2008 08:34:49
singleton Mirko Hrovat 22 Oct 2008 08:34:49
squish Mirko Hrovat 22 Oct 2008 08:34:49
matrix manipulation Mirko Hrovat 22 Oct 2008 08:34:49

Contact us at files@mathworks.com