MATLAB: How to modify vector

MATLAB

I wanted to modify this vector y= 3*x -1 by randomly adding or subtracting 0.5 to every element in the in it. Using rand and while loop.

Best Answer

What vector? Is x a vector? Why do you possibly need a while loop?
y = y + round(rand(size(y))) - 0.5;
So round(rand(size(y))) is randomly 0 or 1, with 50% chance for either. Subtract 1/2, and you will effectively randomly add or subtract .5.