漠漠之堡 发表于 2012-7-3 10:22

麻烦大家帮我看看这段代码是什么意思?

function iid = distmat(X,dmax)

% constrained distance function
% iid ->


n   = size(X,1);%返回x的行数
nrdim = size(X,2);%返回x的列数(实验变差函数的计算维数)
if size(X,1) < 1000;
    = find(triu(true(n)));
    if nrdim == 1;
      d = abs(X(i)-X(j));
    elseif nrdim == 2;
      d = hypot(X(i,1)-X(j,1),X(i,2)-X(j,2));
    else
      d = sqrt(sum((X(i,:)-X(j,:)).^2));
    end
    I = d<=dmax;
    iid = ;
else
    ix = (1:n)';
    if nrdim == 1;
      iid = arrayfun(@distmatsub1d,(1:n)','UniformOutput',false);
    elseif nrdim == 2;
      % if needed change distmatsub to distmatsub2d which is numerically
      % better but slower
      iid = arrayfun(@distmatsub,(1:n)','UniformOutput',false);
    else
      iid = arrayfun(@distmatsub,(1:n)','UniformOutput',false);
    end
    nn= cellfun(@(x) size(x,1),iid,'UniformOutput',true);
    I   = nn>0;
    ix= ix(I);
    nn= nn(I);
    nncum = cumsum(nn);
    c   = zeros(nncum(end),1);
    c() = 1;
    i = ix(cumsum(c));
    iid = ;
   
end

function iid = distmatsub1d(i)
    j= (i+1:n)';
    d= abs(X(i)-X(j));
    I= d<=dmax;
    iid = ;
end

function iid = distmatsub2d(i)%#ok<DEFNU>
    j= (i+1:n)';
    d = hypot(X(i,1) - X(j,1),X(i,2) - X(j,2));
    I= d<=dmax;
    iid = ;
end
   
function iid = distmatsub(i)
    j= (i+1:n)';
    d = sqrt(sum(bsxfun(@minus,X(i,:),X(j,:)).^2,2));
    I= d<=dmax;
    iid = ;
end
end

ChaChing 发表于 2012-7-11 23:59

5.建议提问的网友分清 编程问题 和 专业问题 http://forum.vibunion.com/thread-36746-1-1.html
页: [1]
查看完整版本: 麻烦大家帮我看看这段代码是什么意思?