How to approximate value of array according to specific ratio/ Error percentage
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Bruno Luong
il 19 Lug 2020
round(y)
2 Commenti
Bruno Luong
il 19 Lug 2020
Modificato: Bruno Luong
il 19 Lug 2020
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)
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!