title: MATLAB: How To Efficiently Remove NaN Elements from Matrix
body: <p>I am looking for a way to remove the NaN numbers from a matrix in MATLAB efficiently (i.e. without using a for loop)</p>
  
  <p>I will provide a quick example to illustrate what I am trying to achieve:</p>
  
  <p>Say I have a matrix M:</p>
  
  <pre><code>          3.00          1.00
            1.00          3.00
             NaN           NaN
            3.00          3.00
            1.00          1.00
             NaN           NaN
             NaN           NaN
             NaN           NaN
             NaN           NaN
             NaN           NaN
  </code></pre>
  
  <p>I would like to find a way to change this to</p>
  
  <pre><code>          3.00          1.00
            1.00          3.00
            3.00          3.00
            1.00          1.00
  </code></pre>
  
  <p>I am currently trying to do this via M(isfinite(M)) but that ends up returning a vector instead of the matrix. Is there a trick to have it return a matrix instead?</p>