LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number interpolation..

My input is a fractional decimal number from 1 to 20000. The output can be either 100, 200,400,800. The output should be selected according to the  princeple: For output choose the nearest  of the 4 intergers to the input number. If for example the input value will be 150   then the biggest nearest number will be selected 200.     Example ;
In   Out
1      100
250   200
300   400
2000  800

I have an idea to write a formula node for the solution. But before that I wanted to see maybe there is a nice way to use just LV to solve this problem. I am not asking for code  just for ideas. But code will be nice too. Smiley Happy
Thanks.


0 Kudos
Message 1 of 5
(2,684 Views)
Here's one possibility (if two are the same distance, it will pick the lower one, e.g. 300->200).
 
 
It finds the element with the lowests absolute difference to the input. Modify as needed.
 
 
 
(The "interpolate 1D" function from the math palette also has a "Nearest" method)


Message Edited by altenbach on 06-30-2008 04:32 PM
Message 2 of 5
(2,679 Views)
Seems to work...



Ahhh... you beat me to it altenbach... (I'm pretty chuffed your solution is almost identical to mine though 😉


Message Edited by Troy K on 07-01-2008 09:58 AM
Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
Message 3 of 5
(2,671 Views)


Troy K wrote:
Ahhh... you beat me to it altenbach...
See, that's what happens if you waste your time with annotations and such. 😄

***
 
RSibagatullin, if you want to always round up if there are two choices, just reverse the array.
Message 4 of 5
(2,649 Views)


if you want to always round up if there are two choices, just reverse the array.

Doh! Why didn't I think of that... "much to learn (I) still have".
Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
0 Kudos
Message 5 of 5
(2,645 Views)