Main Content

rescale

Scale range of array elements

Description

example

B= rescale(一个)scales the entries of an array to the interval [0,1]. The output arrayBis the same size as一个.

example

B= rescale(一个,l,u)scales the entries of an array to the interval [l,u].

example

B= rescale(___,Name,Value)specifies additional parameters for scaling an array for either of the previous syntaxes. For example,rescale(A,'InputMin',5)sets all elements in一个that are less than 5 equal to 5 before scaling to the range [0,1].

Examples

全部折叠

Scale the entries of a vector to the interval [0,1].

一个= 1:5; B = rescale(A)
B =1×50 0.2500 0.5000 0.7500 1.0000

Scale the elements of a vector to the interval [-1,1].

一个= 1:5; B = rescale(A,-1,1)
B =1×5-1.0000 -0.5000 0 0.5000 1.0000

Scale each column of a matrix to the interval [0,1] by specifying the minimum and maximum of each column.rescalescales along the dimension of the input array that corresponds with the shape of the'InputMin'and'InputMax'parameter values.

一个= magic(3)
一个=3×38 1 6 3 5 7 4 9 2
colmin = min(A)
colmin =1×33 1 2
colmax = max(A)
colmax =1×38 9 7
Bcol = rescale(A,'InputMin',colmin,'InputMax',colmax)
Bcol =3×31.0000 0 0.8000 0 0.5000 1.0000 0.2000 1.0000 0

Scale each row of一个to the interval [0,1].

rowmin = min(A,[],2)
rowmin =3×11 3 2
rowmax = max(A,[],2)
rowmax =3×18 7 9
Brow = rescale(A,'InputMin',rowmin,'InputMax',rowmax)
Brow =3×31.0000 0 0.7143 0 0.5000 1.0000 0.2857 1.0000 0

Input Arguments

全部折叠

Input array, specified as a scalar, vector, matrix, or multidimensional array.

  • If一个has typesingle, then the output also has typesingle. Otherwise, the output has typedouble.

  • If一个is a scalar, thenrescalereturns the lower bound of the interval (0 by default) orNaN(when the output range containsInf).

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical

Lower bound, specified as a scalar, vector, matrix, or multidimensional array.lmust have a size that is compatible with the input array. For example, if一个is anM-by-Nmatrix, thenrescaleoperates along the dimension dictated by the shape ofl:

  • Iflis a scalar, thenrescaleuses it as the lower bound for all elements of一个.

  • Iflis a 1-by-Nrow vector, thenrescaleuses each element as the lower bound for the corresponding column of一个.

  • Iflis anM-by-1 column vector, thenrescaleuses each element as the lower bound for the corresponding row of一个.

For more information on compatible array sizes, seeCompatible Array Sizes for Basic Operations.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Upper bound, specified as a scalar, vector, matrix, or multidimensional array.umust have a size that is compatible with the input array. For example, if一个is anM-by-Nmatrix, thenrescaleoperates along the dimension dictated by the shape ofu:

  • Ifuis a scalar, thenrescaleuses it as the upper bound for all elements of一个.

  • Ifuis a 1-by-Nrow vector, thenrescaleuses each element as the upper bound for the corresponding column of一个.

  • Ifuis anM-by-1 column vector, thenrescaleuses each element as the upper bound for the corresponding row of一个.

For more information on compatible array sizes, seeCompatible Array Sizes for Basic Operations.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Name-Value Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

Example:B = rescale(A,'InputMin',5,'InputMax',10)

Minimum of input range, specified as a scalar, vector, matrix, or multidimensional array. The default value for an input array一个ismin(A(:)). Specifying an input range either expands or shrinks the range of the input data. For instance,rescalesets all elements that are less than the specified input minimum to the'InputMin'value before scaling.

The'InputMin'value must have a size that is compatible with the input array. For example, if一个is anM-by-Nmatrix, thenrescaleoperates along the dimension dictated by the shape of the input minimum:

  • 如果input minimum is a scalar, thenrescaleuses that minimum value for all elements of一个.

  • 如果input minimum is a 1-by-Nrow vector, thenrescaleuses each element as the minimum for the corresponding column of一个.

  • 如果input minimum is anM-by-1 column vector, thenrescaleuses each element as the minimum for the corresponding row of一个.

For more information on compatible array sizes, seeCompatible Array Sizes for Basic Operations.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical

Maximum of input range, specified as a scalar, vector, matrix, or multidimensional array. The default value for an input array一个ismax(A(:)). Specifying an input range either expands or shrinks the range of the input data. For instance,rescalesets all elements that are greater than the specified input maximum to the'InputMax'value before scaling.

The'InputMax'value must have a size that is compatible with the input array. For example, if一个is anM-by-Nmatrix, thenrescaleoperates along the dimension dictated by the shape of the input maximum:

  • 如果input maximum is a scalar, thenrescaleuses that maximum value for all elements of一个.

  • 如果input maximum is a 1-by-Nrow vector, thenrescaleuses each element as the maximum for the corresponding column of一个.

  • 如果input maximum is anM-by-1 column vector, thenrescaleuses each element as the maximum for the corresponding row of一个.

For more information on compatible array sizes, seeCompatible Array Sizes for Basic Operations.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical

一个lgorithms

B = rescale(A,l,u,'InputMin',inmin,'InputMax',inmax)uses the formula

l + [(A-inmin)./(inmax-inmin)].*(u-l)

to scale the elements of an array一个when the values of一个are within the bounds ofinminandinmax.

  • Iflanduare not specified, thenrescaleuses the default values 0 and 1, respectively.

  • 如果'InputMin'name-value pair is not specified, thenrescalesets its value to the defaultmin(A(:)).

  • 如果'InputMax'name-value pair is not specified, thenrescalesets its value to the defaultmax(A(:)).

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

|||

Introduced in R2017b