24小时热门版块排行榜    

查看: 3796  |  回复: 4

wind5fsa

金虫 (小有名气)

[求助] 报错求教Undefined functionfor input arguments of type 'double'.

大家好,我的matlab程序里面有一部分是我在网上下的一个拟合椭圆的程序,该部分程序如下所示,能将我程序前面部分得到的坐标为(X,Y)的一堆数拟合成椭圆,写完之后一直顺利计算。但是最近忽然报错:
Undefined function 'fitellipse' for input arguments of type 'double'.
Error in F0_1Single_4zhang_ZXEDGEDINGDIAN (line 323)

PS:323这一行的程序是: fitellipse(nx,ny)

然后再怎么运行也都是这么报错。求指教,谢谢!

if nargin == 0
% Create an ellipse
t = linspace(0,2);
Rx = 300
Ry = 200
Cx = 250
Cy = 150
Rotation = .4 % Radians
x = Rx * cos(t);
y = Ry * sin(t);
nx = x*cos(Rotation)-y*sin(Rotation) + Cx;
ny = x*sin(Rotation)+y*cos(Rotation) + Cy;
% Draw it
plot(nx,ny,'o');
% Fit it
fitellipse(nx,ny)
% Note it returns (Rotation - pi/2) and swapped radii, this is fine.
return
end
% normalize data
mx = mean(X);
my = mean(Y);
sx = (max(X)-min(X))/2;
sy = (max(Y)-min(Y))/2;
x = (X-mx)/sx;
y = (Y-my)/sy;
% Force to column vectors
x = x(;
y = y(;
% Build design matrix
D = [ x.*x x.*y y.*y x y ones(size(x)) ];
% Build scatter matrix
S = D'*D;
% Build 6x6 constraint matrix
C(6,6) = 0; C(1,3) = -2; C(2,2) = 1; C(3,1) = -2;
% Solve eigensystem
[gevec, geval] = eig(S,C);
% Find the negative eigenvalue
I = find(real(diag(geval)) < 1e-8 & ~isinf(diag(geval)));
% Extract eigenvector corresponding to negative eigenvalue
A = real(gevec(:,I));
% unnormalize
par = [
A(1)*sy*sy,   ...
      A(2)*sx*sy,   ...
      A(3)*sx*sx,   ...
      -2*A(1)*sy*sy*mx - A(2)*sx*sy*my + A(4)*sx*sy*sy,   ...
      -A(2)*sx*sy*mx - 2*A(3)*sx*sx*my + A(5)*sx*sx*sy,   ...
      A(1)*sy*sy*mx*mx + A(2)*sx*sy*mx*my + A(3)*sx*sx*my*my   ...
      - A(4)*sx*sy*sy*mx - A(5)*sx*sx*sy*my   ...
      + A(6)*sx*sx*sy*sy   ...
      ]';
% Convert to geometric radii, and centers
thetarad = 0.5*atan2(par(2),par(1) - par(3));
cost = cos(thetarad);
sint = sin(thetarad);
sin_squared = sint.*sint;
cos_squared = cost.*cost;
cos_sin = sint .* cost;
Ao = par(6);
Au =   par(4) .* cost + par(5) .* sint;
Av = - par(4) .* sint + par(5) .* cost;
Auu = par(1) .* cos_squared + par(3) .* sin_squared + par(2) .* cos_sin;
Avv = par(1) .* sin_squared + par(3) .* cos_squared - par(2) .* cos_sin;
% ROTATED = [Ao Au Av Auu Avv]
tuCentre = - Au./(2.*Auu);
tvCentre = - Av./(2.*Avv);
wCentre = Ao - Auu.*tuCentre.*tuCentre - Avv.*tvCentre.*tvCentre;
uCentre = tuCentre .* cost - tvCentre .* sint;
vCentre = tuCentre .* sint + tvCentre .* cost;
Ru = -wCentre./Auu;
Rv = -wCentre./Avv;
Ru = sqrt(abs(Ru)).*sign(Ru);
Rv = sqrt(abs(Rv)).*sign(Rv);
a = [uCentre, vCentre, Ru, Rv, thetarad];
回复此楼
祝福
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

baobiao007

木虫 (职业作家)

中国特色

自己进行单步运行调试,应该很容易锁定问题出错的地方吧。
我同意叔本华的观点,人们投身艺术和科学领域的强烈愿望之一就是逃离痛苦、残酷和枯燥无味的现实生活,逃离自己飘忽不定的七情六欲的桎梏。--爱因斯坦
2楼2013-10-31 20:25:42
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wind5fsa

金虫 (小有名气)

引用回帖:
2楼: Originally posted by baobiao007 at 2013-10-31 20:25:42
自己进行单步运行调试,应该很容易锁定问题出错的地方吧。

我发现只要改一下M文件的名就能成功运行了!但是过一会又报错,再改下M文件名又可以了!到底为什么?是因为我工作路径里没有 fitellipse这个M文件吗?求指教:避免这种情况再出现的方法,谢谢!!!
祝福
3楼2013-10-31 23:02:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wind5fsa

金虫 (小有名气)

我发现只要改一下M文件的名就能成功运行了!但是过一会又报错,再改下M文件名又可以了!到底为什么?是因为我工作路径里没有 fitellipse这个M文件吗?求指教:避免这种情况再出现的方法,谢谢!!!
祝福
4楼2013-10-31 23:02:55
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

benbenzjx

金虫 (小有名气)

【答案】应助回帖

文件开头function 名字和参数有没有定义正确?然后把文件名改成fitellipse
5楼2013-11-08 17:14:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 wind5fsa 的主题更新
信息提示
请填处理意见