lsqcurvefit error when using example

1 Ansicht (letzte 30 Tage)
Nathan
Nathan am 7 Jul. 2011
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] = ...

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 7 Jul. 2011
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 Kommentare
Nathan
Nathan am 7 Jul. 2011
No other 'myfun'. I am running a trial of R2011a, and R2007b is still on my machine, but no paths cross.
Nathan
Nathan am 7 Jul. 2011
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Downloads finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by