MATLAB: Finding a range in an array

MATLAB

I have an array of 8000 values. I want to find a range of particular values say for example the values which are between 20 – 25.6 should be multiplied by -1 but the values should be in changed in the same array. I am currently using a the find nested in an if but somehow I cannot store it in the same array.

Best Answer

idx = (array>=20) & (array<=25.6);
array(idx) = -array(idx)