I have two matrices, for example X = [1 2; 3 4; 5 6] and Y = [0 1; -eleven; eleven]. I want to do element separation X./Y, but I need a way to ignore all zeros in Y.
I tried using something like:
nonzeros = find (Y ~ = 0); X (non-zero) ./ Y (non-zero);
but the result has become a column vector, and I need the shape of the result matrix so that it is the same as X (or Y), and with zeros, where Y is zero. Therefore, my desired result for this case is [0 2; -3 4; 5 6].
I also tried what was suggested here ( Right Array Division: Ignoring division by zero ), but at the same time the result again becomes a column vector.
thank
Danny source
share