Skip to content

Instantly share code, notes, and snippets.

@saralilyb
Last active February 29, 2016 18:57
Show Gist options
  • Save saralilyb/edc07b1fbccde8709f04 to your computer and use it in GitHub Desktop.
Save saralilyb/edc07b1fbccde8709f04 to your computer and use it in GitHub Desktop.
Rescales an array so all values lie between a and b, where m is the unscaled array's (potential) minimum value and M is the max. Requires the NumericJS library. Based on Gabriel Peyre's MATLAB code: http://www.mathworks.com/matlabcentral/fileexchange/5103-toolbox-diffc/content/toolbox_diffc/toolbox/rescale.m
rescale_core = (y, a, b, m, M) ->
y if M - m < .0000001
numeric.add(numeric.mul(b - a, numeric.div(numeric.sub(y, m), M - m)), a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment