title: Matlab: change vector values based on if-else condition on the same vector
body: <p>I have a threshold requirement and would like to round values of a vector to 0 or 1. I don't need to save the old values of the vector</p>
  
  <p>I saw, in the link below, that I could use the following to change the all values of 0 in the <code>s</code> vector to -1 with <code>s( s==0 )=-1</code>; or in general <code>vector(if condition) = desiredValue</code>.</p>
  
  <p>This is better than using a for loop and having an enclosed if condition. What if I would like to include another condition: to change all values greater than 0.8 to 1? Would I have to add another line of code:<code>s( s&gt;=0.8 )=1</code>; or is there a way of checking the two conditions by traversing the vector just once? I only know of using a for loop with an enclosed if-else condition but would like a shorter version if one exists.</p>
  
  <p><a href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/158413" rel="nofollow noreferrer">https://www.mathworks.com/matlabcentral/newsreader/view_thread/158413</a></p>
  
  <p>The only related link I found was for R but I am not working with it: <a href="https://stackoverflow.com/questions/39670638/change-vector-value-based-on-value-in-same-vector">Change vector value based on value in same vector</a></p>