problem using nlinfit

조회 수: 7 (최근 30일)
Thibaut
Thibaut 2011년 2월 16일
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

채택된 답변

the cyclist
the cyclist 2011년 2월 16일
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
the cyclist
the cyclist 2011년 2월 16일
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 2011년 2월 18일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by