Vectorized ifs do not exist, but there are some options. If you want to test all or any elements of true, use all or any function.
Here is one example of conditionally changing matrix values:
b = A ~= 0; % b is a boolean matrix pointing to nonzero indices
% (b could be derived from some other condition,
% like b = sin(A)>0
A(b) = f(A(b)) % do something with the indices that pass
A(~b) = g(A(~b)) % do something else with the indices that fail
source
share