From: Alan Weiss on
On 6/9/2010 5:05 PM, Eli Melaas wrote:
> I am trying to use the lsqcurvefit function as such:
>
> M.file - "Phenocam"
> 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]; % Starting guess
> [x,resnorm] = lsqcurvefit(@my_fun_Phenocam,x0,xdata,ydata);
>
> M.file - "my_fun_Phenocam"
> function F = my_fun_Phenocam(x,xdata)
> F = x(1)*exp(x(2)*xdata);
>
> ......and I am consistently getting the following error message:
> ??? Error using ==> feval
> Undefined function or method 'my_fun_Phenocam' for input arguments of
> type 'double'.
> Error in ==> lsqcurvefit at 209
> initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
> Caused by:
> Failure in initial user-supplied objective function evaluation.
> LSQCURVEFIT cannot continue.
>
> Any ideas what is wrong with my code?
>
> Thanks!

Make sure your file my_fun_Phenocam.m is on the MATLAB path. Enter
which my_fun_Phenocam
and you will probably find that MATLAB cannot find the file.

You could use an anonymous function with such a simple objective:
F = @(x,xdata)x(1)*exp(x(2)*xdata);
[x,resnorm] = lsqcurvefit(F,x0,xdata,ydata);

Alan Weiss
MATLAB mathematical toolbox documentation