# Problem in defining the fit type function for curve fitting tool

1 ビュー (過去 30 日間)
Shaily_T 2022 年 5 月 24 日
コメント済み: Shaily_T 2022 年 5 月 26 日
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.
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)));
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 件のコメント表示非表示 1 件の古いコメント
Shaily_T 2022 年 5 月 24 日
Yes, you are correct. Thanks for capturing that! By "x" I mean "nu" in my code. I edditted my question.

サインインしてコメントする。

### 回答 (1 件)

Matt J 2022 年 5 月 24 日

fittype( @(nu,numGaussians,a,sigma) SCR(nu,numGaussians,a,sigma),'independent','nu')
##### 10 件のコメント表示非表示 9 件の古いコメント
Shaily_T 2022 年 5 月 26 日
Yes, that is correct. It is a different issue than what I posted. I posted the question then I was able to make some changes to the fit type function and I see it is working like this which doesn't make sense as the main problem is if I put the obtained fitting parameters in the fit type function I don't see the same result as the fitted curve. I will post another question for it.
Thanks for your time and consideration!

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by