Problem in defining the fit type function for curve fitting tool
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have defined a custom function for use in curve fitting toolbox. In my defined function, I need to call another function "kkrebook2" and its inputs are vectors. But for defining a fit type function we have a for loop of our "nu" value and everything is defined in that for loop which means the input for "kkrebook2" will be elements of vector of "nu". So, it doesn't work when I try to fit because it is getting elements instead of vectors.
But I do want to pass a vector of "nu" to "kkrebook2" in my fit type function. Could you please let me know how can I write my fit type function such that I can call "kkrebook2" in my fit type function properly?
This is related part of my code for the defined fit type function for curve fitting and the "kkrebook2" function.
Thank you in advance!
function p = SCR(nu,numGaussians,a,sigma)
for i = 1:length(nu)
for k = 1 : numGaussians
if k==1
b = Start;
else
b = Start+(24E6 * (k-1));
end
thisGaussian(i) = a.*exp(-((nu(i)-b).^2)/(2.*(sigma.^2)));
% Add into accumulator array:
gaussEqn1(i) = gaussEqn1(i) + thisGaussian(i);
d(i)= gaussEqn1(i);
end
Imag(i)=(-log(d(i))*c)./(nu(i));
Real(i)=kkrebook2(nu(i),Imag(i),0);
f(i)=(-r1+r2*exp(-(d(i)).*exp(-1i*Real(i)));
g(i)=(1-r1*r2*exp(-(d(i))).*exp(-1i*Real(i)));
p(i)= abs(f(i)./g(i));
end
end
2 comentarios
Respuestas (1)
Matt J
el 24 de Mayo de 2022
Editada: Matt J
el 24 de Mayo de 2022
fittype( @(nu,numGaussians,a,sigma) SCR(nu,numGaussians,a,sigma),'independent','nu')
10 comentarios
Matt J
el 26 de Mayo de 2022
Editada: Matt J
el 26 de Mayo de 2022
Here is what I see.
Whether or not this is what you expect is a separate issue from your posted question. Your post is asking how to make fit() invoke your model function and receiving ouput of the proper size. It now appears to be doing that, since no error messages are thrown.
As for why you are not seeing fit results that you expect, there are a number of possible reasons. Your start point could be bad. Or, your model and data may be inconsistent with one another.
Ver también
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!