MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   在MATLAB中标准化矩阵的快速技术 (https://www.labfans.com/bbs/showthread.php?t=24260)

poster 2019-12-10 20:48

在MATLAB中标准化矩阵的快速技术
 
我想在Matlab中规范化矩阵的每一列。我尝试了两种实现:

选项A:

mx=max(x); mn=min(x); mmd=mx-mn; for i=1:size(x,1) xn(i,:)=((x(i,:)-mn+(mmd==0))./(mmd+(mmd==0)*2))*2-1; end 选项B:

mn=mean(x); sdx=std(x); for i=1:size(x,1) xn(i,:)=(x(i,:)-mn)./(sdx+(sdx==0)); end 但是,这些选项占用我的数据太多时间,例如在5000x53矩阵上需要3-4秒。因此,有没有更好的解决方案?



[B]回答:[/B]

记住,在MATLAB中,矢量化=速度。

如果A是M x N矩阵,

A = rand(m,n); minA = repmat(min(A), [size(A, 1), 1]); normA = max(A) - min(A); % this is a vector normA = repmat(normA, [length(normA) 1]); % this makes it a matrix % of the same size as A normalizedA = (A - minA)./normA; % your normalized matrix

[url=https://stackoverflow.com/questions/4521593]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:04

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.