lsqcurvefit error when using example

조회 수: 2 (최근 30일)
Nathan
Nathan 2011년 7월 7일
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에서 Nonlinear Optimization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by