How does Squeeze work?
Show older comments
Hello all,
Can anybody explain me what Squeeze is used for? I have read about it in MATLAB help but I am still confused !
Thanks a lot :-)
Accepted Answer
More Answers (1)
James Tursa
on 1 May 2011
3 votes
The squeeze function is similar to reshape in that it changes the dimensions of a variable without moving any of the data in memory. The total number of elements and their ordering in memory remain the same. For squeeze, the new dimensions are simply the old dimensions with all singleton (==1) dimensions removed (except 2D inputs are left as is).
As for what it is used for, it may be that the result of some algorithm has left you with a 1x2x1x3 matrix and you need to feed that to a function that needs a 2D input. So you could use squeeze on it to get the 2D input as a 2x3 matrix.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!