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

조회 수: 2 (최근 30일)
Mohamed Jamal
Mohamed Jamal 2020년 7월 19일
편집: Bruno Luong 2020년 7월 19일
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

답변 (1개)

Bruno Luong
Bruno Luong 2020년 7월 19일
round(y)
  댓글 수: 2
Mohamed Jamal
Mohamed Jamal 2020년 7월 19일
편집: Mohamed Jamal 2020년 7월 19일
but if I want for instance to round according to residue 0.7 , it means if residue >0.7 then rounding up, otherwise rounding down ! .. how can I do that in matlab?
I also edited my question because Im asking how to approximate according to specific residue/ratio/error ratio , not specifically 0.5
Bruno Luong
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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by