MATLAB: Add 3 to the values of x that are even

add a number to the values of x that are evenevenodd

x=[7 6 1 2 0 -1 4 3 -2 0]
how do I do this in smart short way?

Best Answer

Hi,
x(find(mod(x,2) == 0)) = x(find(mod(x,2) == 0)) + 3
or
ind = find(mod(x,2) == 0);
x(ind) = x(ind) + 3;