An example would clarify what you want. Possibly:
To replace all zero values in A by consecutive values in B, B must have as many elements as there are zeros in A:
assert(numel(B) == numel(A == 0));
A(A == 0) = B
or to replace zeros values in A by values in B in the same position, B must be the same size as A:
A(A == 0) = B(A == 0)
An if is most likely not needed.