声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 794|回复: 1

[编程技巧] 请教函数调用中@的用法

[复制链接]
发表于 2007-8-19 14:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
请问下面的程序中,不添加,与添加@为什么出现不同结果(添加@出现正确结果,不添加@则会有下面的报错)?谢谢。
程序:
xd=[3.6 7.7 9.3 4.1 8.6 2.8 1.3 7.9 10.0 5.4];
yd=[16.5 150.6 263.1 24.7 208.5 9.9 2.7 163.9 325.0 54.3];
plot(xd,yd,'r*'),hold on
x0=[10 10 10];
[x,resnorm]=lsqcurvefit(@myfun,x0,xd,yd)

函数:
function y=myfun(x,xd)
y=x(1)*xd.^2+x(2)*sin(xd)+x(3)*xd.^3;

报错:

??? Input argument "x" is undefined.

Error in ==> myfun at 2
y=x(1)*xd.^2+x(2)*sin(xd)+x(3)*xd.^3;
Error in ==> experiment at 100
[x,resnorm]=lsqcurvefit(myfun,x0,xd,yd)

[ 本帖最后由 eight 于 2007-8-20 20:30 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-8-20 09:25 | 显示全部楼层
请看lsqcurvefit的调用格式和匿名函数的定义

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-24 01:22 , Processed in 0.057130 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表