MATLAB: How to add 1 to all even numbers and add 3 to all odd numbers in a vector

evenoddvector

I have no idea how to do this.I already created a vector by typing: vec = round(-10 + 35* rand(1,30)); and next I am suppose to add 1 to all the even numbers and add 3 to all odd numbers. Thank you in advance for the help.

Best Answer

vec=vec+1+mod(vec,2)*2;