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

2025-01-21 02:53:18
推荐回答(3个)
回答1:

按这样的格式提供参数:

  1. 将这组数据粘贴到matlab编程页面;

  2. 在页面中输入MappedData = mapminmax(OriginalData, 0, 1);

  3. 按回车键。

一、《MATLAB编程》:

  1. 是2007年科学出版社出版的图书;

  2. 作者是查普曼(StephenJ.Chapman)。

二、内容简介:

  1. 本书为国外高校电子信息类优秀教材(英文影印版)之一;

  2. 本书详细讲述了如何用MATLAB进行程序设计,如何编写清楚、高效的程序;

  3. 书中强调了自上而下的程序设计方法、函数的使用、MATLAB内部工具的使用和数据结构,并指出了一些使用技巧和编程者常犯的错误;

  4. 书可作为工科各专业本科生的教学辅导书,也可作为工程技术人员的参考书。

回答2:

很简单,用函数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;

回答3:

用函数mapminmax,