如何加速这个matlab功能

时间:2015-11-14 06:43:33

标签: matlab vectorization

我有一个函数,它在向量x [m,n]上执行HodgesLehmann鲁棒均值。 n是数据的批次索引,m是样本数。

function HLe = HodgesLehmann(x)

% Obtain dimensions
[m,n] = size(x);

% Create xi and xj values with the i <= j restriction enforced
q = logical(triu(ones(m,m),0));
i = uint32((1:m)'*ones(1,m));
xi = x(i(q),:);
j = uint32(ones(m,1)*(1:m));
xj = x(j(q),:);

% Calculate pairwise means (Walsh averages)
W = (xi+xj)./2;

% Calculate ordinary median of Walsh averages
HLe = median(W);

我正在寻找一种加速此功能的方法,它对于x的大尺寸不能很好地扩展。任何促进这一点的方式也是受欢迎的。

非常感谢。

1 个答案:

答案 0 :(得分:1)

this solution的启发,这是一种可能的(未经过性能测试)改进 -

%// Calculate pairwise means (Walsh averages)
[I,J] = find(bsxfun(@le,[1:m]',[1:m])); %//'
W = (x(J,:) + x(I,:))./2;

%// Calculate ordinary median of Walsh averages
HLe = median(W);