MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] d = sqrt((xd-xb).^2+(yd-yb).^2)报错 (https://www.labfans.com/bbs/showthread.php?t=17872)

尚云520 2012-11-15 22:42

d = sqrt((xd-xb).^2+(yd-yb).^2)报错
 
function [xc , yc , phi2 , phi3] = s_RRR(xb , yb , xd , yd , i2 , i3 , m )
d = sqrt((xd-xb).^2+(yd-yb).^2);
if (d>(i2 - i3))||(d<abs(i2 - i3))
errordlg('不能组装');
else
delta = atan((yd - yb)./(xd - xb));
gama = acos((d.^2 + i2.^2 - i3.^2)./(2 * d * i2));
phi2 = delta + m * gama;
xc = xb + i2.*cos(phi2);
yc = yb + i2.*sin(phi2);
phi3 = atan((yc - yd),(xc - xd));
end

报错:
??? Input argument "xd" is undefined.

Error in ==> s_RRR at 2
d = sqrt((xd-xb).^2+(yd-yb).^2);

这是为什么呢?请教高人

zsy312 2012-11-15 23:36

回复: d = sqrt((xd-xb).^2+(yd-yb).^2)报错
 
带有输入值的函数只能调用不能直接执行, 不知道主程序, 所以无法确定是怎么调用的.

[email protected] 2012-11-22 16:45

回复: d = sqrt((xd-xb).^2+(yd-yb).^2)报错
 
没有给xb赋值 输入量在调用程序时必须都给赋值 不然会出现没有定义这样的错误

jimmymacong 2012-11-22 20:31

回复: d = sqrt((xd-xb).^2+(yd-yb).^2)报错
 
函数本身没有问题,一定是你在引用时,赋值错误导致的。
你在引用这个子函数的时候,一定要注意给每个参数都要赋上合乎格式的值,或者要么可以用nargin函数来检测你输入的参量个数,并作相应的处理。良好的编程习惯是:必须检测你的输入量和输出量,并做一定的处理。


所有时间均为北京时间。现在的时间是 05:09

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.