How to approximate value of array according to specific ratio/ Error percentage

1 view (last 30 days)
Hi guys, I have an array y=[0.8 3.7 -0.8 -2.2 5.173 4.133] , I want to do in matlab approximations to my number as this :
if my number residue is bigger than 0.6 then map/add it to 1 or -1 (it depends to the sign of the number), for instance in my example:
0.8 is bigger than 0.6 so I want to approximate it to 1.
3.7 , the residue is 0.7 so it's bigger than 0.6 so I approximate 3.7 to 4 because the residue 0.7 (3.7-3=residue) is bigger than 0.6 so I add one to the complete number.
-0.8 is bigger than 0.6 in abs , mean abs(-0.8)>0.6 so I approimate it to -1
-2.2 the residue is 0.2 <0.6 so I approximate it to 2 and not to 3 because the residue (abs(-2.2)-2 = 0.2) is smaller than 0.6 so I'm not adding one to the complete number ..
4.133 , the residue is 0.133<0.6 so I approximate it to 4 and not adding one to complete number (4) because the residue 0.133 is smaller than 0.6 ..
etc ..
the rule is : whenver the residue of the number(modulo of the number) bigger than 0.6 then we are rounding up the number(rounding up the current value of the array), otherwise we are rounding down the number(rounding down the current value of the array).
could anyone please help me how can I implement that in matlab? thanks alot

Answers (1)

Bruno Luong
Bruno Luong on 19 Jul 2020
Bruno Luong
Bruno Luong on 19 Jul 2020
Edited: Bruno Luong on 19 Jul 2020
round(y-(0.7-0.5)) % 0.7 here is the desired threshold, do not change 0.5
or the simplest

Sign in to comment.


Find more on FPGA, ASIC, and SoC Development in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!