problem using nlinfit
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!