Excel Function name to map one ratio to another

2019-08-02 03:35发布

I can't figure out the terminology to search for the function I want:

Anrduino has a map(value,inLo,inHi,outLo,outHi) function that takes a value within IN range and returns the value with the same ratio mapped to the OUT range. For example map(5,0,6,200,380) returns 350 because the value 5 in a range of 0-6 is 5/6 and 5/6 of the range from 200 to 380 is 350.

I can write my own function in Excel but I am guessing there is something built in.

3条回答
姐就是有狂的资本
2楼-- · 2019-08-02 04:00

Actually Charles Williams answer doesnt quite address the equivalent Arduino 'Map' function. A more correct formula is: =((value-inLo)/(inhi-inlo))*(outhi-outlo)

查看更多
走好不送
3楼-- · 2019-08-02 04:00

You mean correct formula is : (from arduino.cc/en/Reference/Map) long map(long x, long in_min, long in_max, long out_min, long out_max)

{return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;}

(you forgot +out_min at the end)

查看更多
唯我独甜
4楼-- · 2019-08-02 04:03

Very good explanation is given by James Ramsden here: http://james-ramsden.com/map-a-value-from-one-number-scale-to-another-formula-and-c-code/

Essentially if one scale is from a0 to a1 and other scale is from b0 to b1 and you want to map the value a to some value of b. The equation is:

enter image description here

查看更多
登录 后发表回答