rescale

Rescales data linearly to a given interval.

Category: Data Import and Analysis > Preprocessing Data

Syntax

B = rescale(A)

Maps the data to the interval from 0 to 1.

B = rescale(A, l, u)

Maps the data to the interval from l to u.

B = rescale(___, 'InputMin', a, 'InputMax', b)

Treats a and b as the input limits instead of the data extremes.

Description

The mapping is linear: l + (A - min) .* (u - l) ./ (max - min), where min and max are the extremes of the whole array unless InputMin and InputMax are given. Unlike normalize, the extremes are taken over all elements, not column by column.

Setting the input limits is useful to scale new data with the limits of a reference set, for example turning a sensor range into percentages.

Input arguments

A
Numeric array.
l, u
Lower and upper limit of the output.
'InputMin', 'InputMax'
Input values that map to l and u.

Output arguments

B
Array of the same size as A.

Example

Into 0 to 1, and with fixed input limits

x = [1 2 3 4];
rescale(x)
rescale(x, -1, 1)
rescale(x, 0, 10, 'InputMin', 0, 'InputMax', 8)
Output
ans = 1×4

         0    0.3333    0.6667    1.0000
ans = 1×4

   -1.0000   -0.3333    0.3333    1.0000
ans = 1×4

    1.2500    2.5000    3.7500    5.0000

See also

normalize bounds