Main Content

mapminmax

Process matrices by mapping row minimum and maximum values to [-1 1]

Description

Tip

To rescale data for deep learning workflows, use the Normalization name value pair for the input layer.

[Y,PS] = mapminmax(X,YMIN,YMAX) takes a N-by-Q matrix, X and optionally a minimum and a maximum value for each row of Y, YMIN and YMAX, and returns a N-by-Q matrix, Y, and a process settings that allow consistent processing of values, PS.

mapminmax processes matrices by normalizing the minimum and maximum values of each row to [YMIN, YMAX].

example

[Y,PS] = mapminmax(X,FP) takes parameters as a struct: FP.ymin, FP.ymax.

Y = mapminmax('apply',X,PS) returns Y, given X and settings PS.

X = mapminmax('reverse',Y,PS) returns X, given Y and settings PS.

dx_dy = mapminmax('dx_dy',X,Y,PS) returns the reverse derivative.

Examples

collapse all

This example shows how to format a matrix so that the minimum and maximum values of each row are mapped to default interval [-1,+1].

x1 = [1 2 4; 1 1 1; 3 2 2; 0 0 0]
[y1,PS] = mapminmax(x1)

Next, apply the same processing settings to new values.

x2 = [5 2 3; 1 1 1; 6 7 3; 0 0 0]
y2 = mapminmax('apply',x2,PS)

Reverse the processing of y1 to get x1 again.

x1_again = mapminmax('reverse',y1,PS)

Input Arguments

collapse all

Matrix you want to process, specified as an N-by-Q matrix.

Minimum value for each row of the output matrix Y, specified as a scalar.

Maximum value for each row of the output matrix Y, specified as a scalar.

Output Arguments

collapse all

Processed matrix, returned as an N-by-Q matrix.

Process settings that allow consistent processing of values, returned as a structure.

More About

collapse all

Algorithms

It is assumed that X has only finite real values, and that the elements of each row are not all equal. (If xmax=xmin or if either xmax or xmin are non-finite, then y=x and no change occurs.)

y = (ymax-ymin)*(x-xmin)/(xmax-xmin) + ymin;

Version History

Introduced in R2006a