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.
Use this -
out = X./Y %// Perform the elementwise division out(Y==0)=0 %// Select the positions where Y is zero and %// set those positions in the output to zero
Output -
X = 1 2 3 4 5 6 Y = 0 1 -1 1 1 1 out = 0 2 -3 4 5 6