title: Matlab element-wise division by zero
body: <p>I have two matrices, say X = [1 2; 3 4; 5 6] and Y = [0 1; -1 1; 1 1]. I want to perform element-wise division X./Y, but I need a way to ignore all the zeros in Y. </p>
  
  <p>I tried using something like:</p>
  
  <p>nonzeros = find(Y ~= 0);
  X(nonzeros) ./ Y(nonzeros);</p>
  
  <p>but doing so caused the result to be a column vector, and I need the shape of the result matrix to be the same as X (or Y) and with zeros where Y was zero. So my desired result for this case is [0 2; -3 4; 5 6].</p>
  
  <p>I also tried what was suggested here (<a href="https://stackoverflow.com/questions/21532826/right-array-division-ignoring-division-by-zeroes">Right Array Division : Ignoring division by zeroes</a>), but doing this again forces the result to be a column vector.</p>
  
  <p>Thanks</p>