I have two data matrices A
and B
of similar dimensions. I intend to divide each element of A
by its corresponding elements of B<
Yes. You can use logical indexing:
C = zeros(size(A));
t = logical(B);
C(t) = A(t)./B(t);
With logical indexing, only the elements of A
, B
and C
corresponding to true
elements of t
will be evaluated. t
is true
only where B
is non-zero. Note that C
is pre-initialized to zeros to automatically take care of the cases that are not evaluated because B
is zero.