How to approximate value of array according to specific ratio/ Error percentage
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Bruno Luong
2020-7-19
round(y)
2 个评论
Bruno Luong
2020-7-19
编辑:Bruno Luong
2020-7-19
round(y-(0.7-0.5)) % 0.7 here is the desired threshold, do not change 0.5
Alternatively
floor(y+(1-0.7))
or the simplest
ceil(y-0.7)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!