Reputation: 4276
I have a variable x
that accepts a range of values from 0 - 500.
I want to represdnt this variable's value in a new variable xScaled
that accepts a range of 0 - 1.
Example:
Given x = 292
what is the relative value of xScaled
and how can this be calculated?
Thanks
Upvotes: 2
Views: 8080
Reputation: 4982
No offence intended, but this is fairly simple arithmetics. Your programming skills will greatly improve if you spend just few minutes a day here: http://www.khanacademy.org/
Upvotes: 1
Reputation: 67380
Divide by the maximum value: (0-500) becomes (0/500-500/500)=(0-1).
So for 292, scaled it becomes 292/500.
Upvotes: 2
Reputation: 881523
You seem to be asking for the formula:
xScaled = x / 500
For a more general solution, the following pseudo-code can map one range to another:
def mapRange (x, from_min, from_max, to_min, to_max):
return (x - from_min) * (to_max - to_min) / (from_max - from_min) + to_min
Upvotes: 4