lsqcurvefit error when using example

1 次查看(过去 30 天)
When I copy/paste
myfun = @(x,xdata) x(1)*exp(x(2)*xdata);
% Assume you determined xdata and ydata experimentally
xdata = [0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
ydata = [455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
x0 = [100; -1];
[x] = lsqcurvefit(myfun,x0,xdata,ydata);
into the command window I get the following error.
??? Attempt to reference field of non-structure array.
Error in ==> optimget>optimgetfast at 95
value = defaultopt.(name);
Error in ==> optimget at 25
o = optimgetfast(options,name,default);
Error in ==> lsqncommon at 24
switch optimget(options,'Display',defaultopt,'fast')
Error in ==> lsqcurvefit at 182
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...

采纳的回答

Sean de Wolski
Sean de Wolski 2011-7-7
myfun = @(x,xdata) x(1)*exp(x(2)*xdata);
% Assume you determined xdata and ydata experimentally
xdata = [0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
ydata = [455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
x0 = [100; -1];
[x] = lsqcurvefit(myfun,x0,xdata,ydata);
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the default value of the function tolerance.
stopping criteria details
x
x =
498.83
-0.10126
myfun(x,xdata)
ans =
Columns 1 through 7
455.38 428.54 123.34 67.18 43.466 28.698 14.126
Columns 8 through 10
1.1124 0.26145 0.13267
Works for me. Do you have another function 'myfun' somewhere?
  2 个评论
Nathan
Nathan 2011-7-7
No other 'myfun'. I am running a trial of R2011a, and R2007b is still on my machine, but no paths cross.
Nathan
Nathan 2011-7-7
I take that back, no myfun.m lying around, but I had a rouge lsqcurvefit.m for some reason. Removed the old lsqcurvefit.m, kept the new, things work now.
Thanks for the inspiration to clean up my own mess.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by