Calling a custom function in fittype

8 ビュー (過去 30 日間)
David
David 2015 年 11 月 27 日
コメント済み: Oisín Conway 2022 年 10 月 7 日
Hi,
I am attempting to create a custom fit, which itself calls a simple function.
In a separate .m file I define a function for finding the full width at half maximum of a curve ("Y"):
function[F05] = FWHMf(x,Y)
[~,b] = min(abs(Y-0.5));
F05 = 2*abs(x(b));
I then call this function in my main .m file thus:
F3 = @(w,x,q,S) FWHMf(x,exp(-x.^2./(q+w^2)));
CF3 = fittype(F3,'coefficients','w','independent',{'x','q'},'dependent','S');
Where, I have measured "S" as function of "q", and I wish to find the parameter "w" using the fit.
This code produces an error:
"Custom equations must produce an output vector, matrix, or array that is the same size and shape as the input data. This custom equation fails to meet that requirement"
when run in Matlab version 2014b.
I know I must be doing something wrong here, perhaps in my entire approach to the problem. Any suggestions would be greatly appreciated.
Cheers,
David

回答 (1 件)

David
David 2015 年 11 月 30 日
In case it simplifies the situation at all, I have rewrote the FWHMf function to:
function[F05] = FWHMf(x,Y)
F05 = 2*sqrt(log(2))*sum(x.^2.*Y)/sum(Y);
I've tried a few different things but still can't get the code to define the fittype without throwing up an error.
  1 件のコメント
Oisín Conway
Oisín Conway 2022 年 10 月 7 日
Hello @David, was this solved in the end?

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

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by