473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

rescale a range of numbers

Joe
I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).

I thought there was a way to do this by adding 255 but I can't remember how.

Any suggestions?

-Joe
Aug 30 '07 #1
6 4255
You want to apply linear interpolation, between two known points.
http://en.wikipedia.org/wiki/Linear_interpolation

"Joe" <jb*******@noemail.noemailwrote in message
news:uq**************@TK2MSFTNGP06.phx.gbl...
>I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).

I thought there was a way to do this by adding 255 but I can't remember
how.

Any suggestions?

-Joe

Aug 30 '07 #2
"Joe" <jb*******@noemail.noemailwrote in message
news:uq**************@TK2MSFTNGP06.phx.gbl...
>I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).
range1 = 26.43534;
range2 = 234.24;
target1 = 0;
target2 = 255;
valueToPlace = 118.12;
scale = (rage2-range1)/(target2-target1);
result = target1+(valueToPlace-range1)/scale;

Or, in this case, 112.50

Aug 30 '07 #3
Joe
Perfect - Thanks!

"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:%2******************@TK2MSFTNGP03.phx.gbl...
"Joe" <jb*******@noemail.noemailwrote in message
news:uq**************@TK2MSFTNGP06.phx.gbl...
>>I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).

range1 = 26.43534;
range2 = 234.24;
target1 = 0;
target2 = 255;
valueToPlace = 118.12;
scale = (rage2-range1)/(target2-target1);
result = target1+(valueToPlace-range1)/scale;

Or, in this case, 112.50

Aug 30 '07 #4
Joe
I ran into a case when this doesn't work.

range1 = 0;
range2 = 60;
valueToPlace = 86.658;

my result = 368.29650000000004.

-Joe

"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:%2******************@TK2MSFTNGP03.phx.gbl...
"Joe" <jb*******@noemail.noemailwrote in message
news:uq**************@TK2MSFTNGP06.phx.gbl...
>>I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).

range1 = 26.43534;
range2 = 234.24;
target1 = 0;
target2 = 255;
valueToPlace = 118.12;
scale = (rage2-range1)/(target2-target1);
result = target1+(valueToPlace-range1)/scale;

Or, in this case, 112.50

Sep 5 '07 #5
seems your ValueToPlace is out of range (60). If it is just the last 4
after all the zeroes that you don't like, you can probably eliminate the
rounding error by limiting the number of decimals you display.

/LM
"Joe" <jb*******@noemail.noemailwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
>I ran into a case when this doesn't work.

range1 = 0;
range2 = 60;
valueToPlace = 86.658;

my result = 368.29650000000004.

-Joe

"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:%2******************@TK2MSFTNGP03.phx.gbl...
>"Joe" <jb*******@noemail.noemailwrote in message
news:uq**************@TK2MSFTNGP06.phx.gbl...
>>>I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).

range1 = 26.43534;
range2 = 234.24;
target1 = 0;
target2 = 255;
valueToPlace = 118.12;
scale = (rage2-range1)/(target2-target1);
result = target1+(valueToPlace-range1)/scale;

Or, in this case, 112.50


Sep 5 '07 #6
Joe
Ok so I made myself look like a fool....

Sometimes it's good to sleep.

"Luc E. Mistiaen" <lu**********@advalvas.be.no.spamwrote in message
news:ee**************@TK2MSFTNGP04.phx.gbl...
seems your ValueToPlace is out of range (60). If it is just the last 4
after all the zeroes that you don't like, you can probably eliminate the
rounding error by limiting the number of decimals you display.

/LM
"Joe" <jb*******@noemail.noemailwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
>>I ran into a case when this doesn't work.

range1 = 0;
range2 = 60;
valueToPlace = 86.658;

my result = 368.29650000000004.

-Joe

"Alberto Poblacion" <ea******************************@poblacion.org>
wrote in message news:%2******************@TK2MSFTNGP03.phx.gbl...
>>"Joe" <jb*******@noemail.noemailwrote in message
news:uq**************@TK2MSFTNGP06.phx.gbl...
I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value
falls within it (so the value also needs to be rescaled).

range1 = 26.43534;
range2 = 234.24;
target1 = 0;
target2 = 255;
valueToPlace = 118.12;
scale = (rage2-range1)/(target2-target1);
result = target1+(valueToPlace-range1)/scale;

Or, in this case, 112.50



Sep 5 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
3
by: JoelPJustice | last post by:
I am working through a VBA book by myself to help and try and improve my skills. However, the book does not give you solutions to certain problems. I have worked through this problem up until bullet...
14
by: Anthony Liu | last post by:
I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up...
1
by: johntilster | last post by:
How do I get uniform random numbers in the log domain? I need a random number in the log domain between -infinity and -0.69314718, which is equivalent to a range from 0 to 0.5. I usually use...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
7
by: bipi | last post by:
Dear all, I found function rand(), it can create random number but this function can not define the range of number which I want to get it, such as, I want to get random number in the range from...
3
by: djcamo | last post by:
Hi, I have a situation where I have a collection that holds numbers. Mostly they are concurrent eg. 125801-125899 but sometimes they are not eg. 125801-125899, 195301-399. Is there any way to...
1
by: kreuzen | last post by:
Hi everybody, I'm trying to write a program that checks what the minimum and maximum number out of all the range numbers given. Example: 1-10, 2-20, 3-30 min = 1 max = 30 There are also...
10
by: Rafael Cunha de Almeida | last post by:
Hi, I've found several sites on google telling me that I shouldn't use rand() % range+1 and I should, instead, use something like: lowest+int(range*rand()/(RAND_MAX + 1.0))
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.