matlab:??? “double”类型的输入参数的未定义函数或方法

时间:2012-07-24 20:52:21

标签: matlab

有人可以解释为什么我的代码中出现以下错误?它涉及将双打传递给Z,但我没有看到参数a和b是如何加倍的。

clear all;
im = imread('smallblob.png');
im = im(:,:,1);
w = size(im,1);
h = size(im,2);
[dx,dy] = gradient(double(im));
lambda = 1;
Ox = -1.^lambda.*(-dx);
Oy = -1.^lambda.*(dy);
magO = sqrt(Ox.^2 + Oy.^2);

Ix = dx;
Iy = dy;
magI = sqrt(Ix.^2 + Iy.^2);

N=w+1;
yp(1:N)=-0.5*w:1:0.5*w;
xp(1:N)=-0.5*h:1:0.5*h;
Y(1:w,1:h)=0;
X(1:w,1:h)=0;
for i=1:w
    Y(i,:)=yp(i);
end
for i=1:h
    X(:,i)=xp(i);
end


for a=1:h
    for b=1:w
        for i=1:N-1
            Rx(i)=-0.5*(Ix(i)+Ix(i+1));
            Ry(i)=-0.5*(Iy(i)+Iy(i+1));
            Rz(i)=Z(a,b);                   %HERE IS THE ERROR
            dlx(i)=Ix(i+1)-Ix(i);
            dly(i)=Iy(i+1)-Iy(i);
        end
        Rx(N)=-0.5*(Ix(N)+Ix(1));
        Ry(N)=-0.5*(Iy(N)+Iy(1));
        Rz(N)=Z(a,b);
        dlx(N)=-Ix(N)+Ix(1);
        dly(N)=-Ix(N)+Ix(1);

        for i=1:N
            Xcross(i)=dly(i).*Rz(i);
            Ycross(i)=-dlx(i).*Rz(i);
            Zcross(i)=(dlx(i).*Ry(i))-(dly(i).*Rx(i));
            R(i)=sqrt(Rx(i).^2+Ry(i).^2+Rz(i).^2);
        end

        Bx1=(magI*magO./((R.^3))).*Xcross;
        By1=(magI*magO./((R.^3))).*Ycross;
        Bz1=(magI*magO./((R.^3))).*Zcross;

        BX(a,b)=0;
        BY(a,b)=0;
        BZ(a,b)=0;

        for i=1:N
            BX(a,b)=BX(a,b)+Bx1(i);
            BY(a,b)=BY(a,b)+By1(i);
            BZ(a,b)=BZ(a,b)+Bz1(i);
        end
    end
end



??? Undefined function or method 'Z' for input arguments of type 'double'.

Error in ==> MAC4 at 34
Rz(i)=Z(a,b);

非常感谢!

1 个答案:

答案 0 :(得分:7)

您尝试在定义变量Z之前访问它。在访问其内容之前,您需要为Z分配一个值。