I have an array:
[0.0182, 0.5238, -0.0205, 1.1683, 0.9684, 0.9722, 0.5677, 0.9043, 0.0025, ...
0.9986, 0.4088, 0.5483, -0.0082, 0.5659]
I want to set new numbers in range of [0 0.5 1]
for the above array. For example, 0.5238
is nearer to 0.5
than 1
, so it should be set to 0.5
rather than 1
. 0.0025
is closer to 0
than 0.5
, so it should be set to 0
, and so on. As a result, new array should be:
[0, 0.5, 0, 1, 1, 1, 0.5, 1, 0, 1, 0.5, 0.5, 0, 0.5]
How is it possible in MATLAB? Is there any function?