0
$\begingroup$

I have a sensor system that receives range of values(example is given below). These range values need to be mapped to integer values.

Value Range....... ...Integer

0.000 to 0.049 -----> 0

0.050 to 0.099 -----> 1

0.010 to 0.149 -----> 2

..... ..... ..goes on like this

I need to find the mathematical expression so that whenever the value comes the expression convert it to integer values. It would be great if someone can help me with this. Thanks in advance.

1 Answers 1

1

$f(x)=\lceil 20x-0.98 \rceil$ seems to do the trick.

  • 0
    Thank you for the answer! If I give x=0.010, f(x)=[20*0.010-0.98]=-0.78. It is not an integer. I think there should be a 'round' operation, something like (round(x/0.5))*2( This one doesn't match to the above case)2017-01-18
  • 0
    @Anson The brackets around $20x-0.98$ in the function indicate you round up ([See this](https://en.wikipedia.org/wiki/Floor_and_ceiling_functions#Examples)). For $x=10$, you would have $f(10)= \lceil 20(10)-0.98 \rceil = \lceil -0.78 \rceil = 0$.2017-01-18
  • 0
    @Anson I take it you're implementing this into some kind of program, so you would look for a function named "ceiling" and your code would be something like `ceiling(20*(double x) -0.98)` in Java, for example.2017-01-18
  • 0
    @ Andrew TawfeekThank you so much. By using the ceil operation it is working. Could you please explain how derived this expression?2017-01-18
  • 0
    @Anson Just using general knowledge of how the ceiling function works then scaling it to fit.2017-01-18