matlab 数组 归一化,肿么将一组数据归一化到(0,1)之间,用matlab编程

很简单,用函数mapminmax,文档太长我就不翻译了,只提醒几个关键

1 默认的map范围是[-1, 1],所以如果需要[0, 1],则按这样的格式提供参数:

MappedData = mapminmax(OriginalData, 0, 1);

2 只按行归一化,如果是矩阵,则每行各自归一化,如果需要对整个矩阵归一化,用如下方法:

FlattenedData = OriginalData(:)'; % 展开矩阵为一列,然后转置为一行。

MappedFlattened = mapminmax(FlattenedData, 0, 1); % 归一化。

MappedData = reshape(MappedFlattened, size(OriginalData)); % 还原为原始矩阵形式。此处不需转置回去,因为reshape恰好是按列重新排序

文档全文如下:

mapminmax

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

Syntax

[Y,PS] = mapminmax(YMIN,YMAX)

[Y,PS] = mapminmax(X,FP)

Y = mapminmax('apply',X,PS)

X = mapminmax('reverse',Y,PS)

dx_dy = mapminmax('dx',X,Y,PS)

dx_dy = mapminmax('dx',X,[],PS)

name = mapminmax('name');

fp = mapminmax('pdefaults');

names = mapminmax('pnames');

remconst('pcheck',FP);

Description

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

mapminmax(X,YMIN,YMAX) takes X and optional parameters

X

N x Q matrix or a 1 x TS row cell array of N x Q matrices

YMIN

Minimum value for each row of Y (default is -1)

YMAX

Maximum value for each row of Y (default is +1)

and returns

Y

Each M x Q matrix (where M == N) (optional)

PS

Process settings that allow consistent processing of values

mapminmax(X,FP) takes parameters as a struct: FP.ymin, FP.ymax.

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

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

mapminmax('dx',X,Y,PS) returns the M x N x Q derivative of Y with respect to X.

mapminmax('dx',X,[],PS) returns the derivative, less efficiently.

mapminmax('name') returns the name of this process method.

mapminmax('pdefaults') returns the default process parameter structure.

mapminmax('pdesc') returns the process parameter descriptions.

mapminmax('pcheck',FP) throws an error if any parameter is illegal.

Examples

Here is 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)

Algorithm

It is assumed that X has only finite real values, and that the elements of each row are not all equal.

*

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

取消

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值