You can use logical indexing.
(First I assume a and b have the same length or your question doesn't make sense).
To get a vector that is TRUE when b is negative and FALSE otherwise, you can just do:
b < 0 % depending on what you want, b <= 0
You can use this as an index into a to grab out those corresponding elements:
a( b < 0 )
Now that you've selected the right elements make them negative and assign them back:
a ( b < 0 ) = - a ( b < 0 );
In terms of efficiency, you may want to store the vector b < 0 to avoid re-calculating it (you'll have to try and see which on you prefer):
idx = b < 0;
a(idx) = -a(idx);
Matlab is a vectorised language so most times there is a for loop, you can avoid it. Read up about this sort of matrix indexing here.