If all elements are positive, keep the smallest element of each matrix by doing an element by element comparison :
B2 = min(A,B)
Alternatively, create a logical matrix indicating if a condition is answered and multiply element by element with the matrix
B , only elements who satisfy the condition remain, others are set to zero:
B = B.*(A~=0)
Then keep elements of
B that are smaller or equal to elements of
A, and replace them by the value of
B = B.*(B<=A) + A.*(B>A) )
This option lets you generalize your constraint.
You indicate needing elements of b_ij to be greater than zero if elements of a_ij are greater than zero. An option is to use the function
max to ensure that all elements of
B are positive.
B = max(1e-2,B); % exact value is yours to set.
This step is up to you and depend on your problem.