rescaleVector

Rescale a list of values from one range to another

Information

This information is part of the Business Simulation Library (BSL). Please support this work and ► donate.

The function will rescale the input vector to a vector whose elements run from range y_min to y_max over the range min to max.

Syntax


Function.rescaleVector(x);                             // min = min(vec), max = max(vec), y_min = 0, y_max = 1
Function.rescaleVector(x, {min, max});                 // y_min = 0 , y_max = 1
Function.rescaleVector(x, {min, max}, {y_min, y_max});

Examples


rescaleVector({0,1,2,3,4,5,6,7,8,9,10});    // {0.,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}
rescaleVector({4,5,6},{0, 10});             // {0.4, 0.5, 0.6}
rescaleVector({4,5,6},{0,10},{10,20});      // {14.,15.,16.}

Notes

This function is closely modeled to Rescale in the Wolfram Language.

See also

Functions.rescale

Syntax

y = rescaleVector(x, x_range, y_range)

Inputs (3)

x

Type: Real[:]

Description: List of values (vector) to be rescaled

x_range

Default Value: {min(x), max(x)}

Type: Real[2]

Description: Original range [min,max] given as a list (default = {min(x), max(x)})

y_range

Default Value: {0, 1}

Type: Real[2]

Description: Rescaled range [y_min, y_max] given as a list (default = {0,1})

Outputs (1)

y

Type: Real[size(x, 1)]

Description: Rescaled value to run from y_min to y_max over the range min to max

Revisions

  • Corrected documentation errors, simplified implementation and added Inline = true in v.2.1.0.