problem using nlinfit
5 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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
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.]
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!