problem using nlinfit

5 visualizaciones (últimos 30 días)
Thibaut
Thibaut el 16 de Feb. de 2011
Hi. I'm trying to use nlinfit to fit some experimental data. I keep getting the same error message:
??? Undefined function or method 'nlinfit' for input arguments of type
'function_handle'.
Error in ==> fit_parameter_L at 17
vfit = nlinfit(x, log(exp_data(:,2)), @fun, v0);
I tried to simplify my code as much as possible and to make it look exactly like examples I could find on the Internet (like here: http://www.mathworks.com/matlabcentral/fileexchange/13648-lorentzian-fit, since the example in the Help is useless). In the end it looks like a linear fitting:
x = exp_data(:,1);
v0 = [1 1] ;
vfit = nlinfit(x, log(exp_data(:,2)), @fun, v0);
semilogy( exp_data_max(:,1), exp_data_max(:,2), 'b', ...
exp_data_max(:,1), fun(vfit, exp_data_max(:,1)), 'r' );
with the following "fun" function in a separate .m file:
function [y]=fun(v,x)
a = v(1);
b = v(2);
y = a .* x + b;
I know other, simpler functions could be used to solve this linear problem but I really need to use nlinfit since my initial model contains nonlinear terms. I'm going to extend this version as soon as I can get it work. So can you please tell me what is wrong in the code above? Could there be a problem with the version of Matlab I use?
Thanks.
Tibo

Respuesta aceptada

the cyclist
the cyclist el 16 de Feb. de 2011
That code executes without error for me (if I define the exp_data and exp_data_max variables).
What is the output of
>> which nlinfit
for you? Do you have the Statistics Toolbox?
  3 comentarios
the cyclist
the cyclist el 16 de Feb. de 2011
I would normally expect it return "not found" if you do not have the toolbox, but maybe I am wrong. Sounds like maybe you had the toolbox, but the license expired? Not really sure.
[Also, please accept this answer if it turns out to be correct.]
Thibaut
Thibaut el 18 de Feb. de 2011
All right. I guess that's why so many people get the same error message as me. I'll solve my problem with polyfit and find a trick for the nonlinear part. Thanks for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by