title: How do I create an array corresponding to the non zero elements of another matrix in Matlab
body: <p>How do I create an array corresponding to the non zero elements of another matrix in Matlab?</p>
  
  <p>For example, I have a matrix M as shown here:
  <a href="https://i.stack.imgur.com/Lannl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lannl.png" alt="enter image description here"></a></p>
  
  <p>In Matlab, I want to create an array that only contains the position of the non-zero elements row-wise like this:</p>
  
  <pre><code>Y=[ 1 2 5 6 9 13 17......]
  </code></pre>