在MATLAB中对矩阵进行归一化的快速技术 [英] Fast technique for normalizing a matrix in MATLAB

查看:205
本文介绍了在MATLAB中对矩阵进行归一化的快速技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Matlab中规范化矩阵的每一列.我尝试了两种实现方式:

I want to normalise each column of a matrix in Matlab. I have tried two implementations:

选项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秒.因此,有没有更好的解决方案?

However, these options take too much time for my data, e.g. 3-4 seconds on a 5000x53 matrix. Thus, is there any better solution?

推荐答案

在MATLAB中,请记住向量化=速度.

Remember, in MATLAB, vectorizing = speed.

如果A是M x N矩阵,

If A is an M x N matrix,

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

这篇关于在MATLAB中对矩阵进行归一化的快速技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆