title: MATLAB - Remove Leading and Trailing Zeros From a Vector
body: <p>I have a wavelet function with leading and trailing zeros.  I would like to strip all the zeros which occur before or after the wavelet. However, I would not like to remove any zeros within the wavelet itself.  To simplify, let's say I have the following 1x11 vector:</p>
  
  <pre><code>0 0 0 -2 -1 0 -1 -2 0 0 0
  </code></pre>
  
  <p>After removing leading and trailing zeros the vector should be:</p>
  
  <pre><code>-2 -1 0 -1 -2
  </code></pre>
  
  <p>My actual vectors are large and performance is my primary concern.  I am a MATLAB novice and would appreciate any tips on how to accomplish this task as efficiently as possible.     </p>