フィルターのクリア

How to define a constant inside the 'fittype' function?

22 ビュー (過去 30 日間)
Anup
Anup 2022 年 11 月 6 日
回答済み: Steven Lord 2022 年 11 月 6 日
function [fitresult, gof] = createFit(i1, v1,s,T1)
[xData, yData] = prepareCurveData( i1, v1 );
% Set up fittype
ft = fittype( '1.21+(a1+a2.*T1).*x+s.*log((b1+b2./T1+b3./T1.^2).*x+1)', 'independent', 'x', 'dependent', 'y');
Here s and T1 are constant values passed by the function 'createFit()'.
a1,a2,b1,b2,b3 are parameters to be determined based on independent value 'i1' and dependent value 'v1'.
Currently in my code, fittype is treating 's' and 'T' also as parameters.
Is there a way such that fittype function treat 's' and 'T1' as constant values passed from the function but not as the parameters?

採用された回答

John D'Errico
John D'Errico 2022 年 11 月 6 日
Use a function handle, as documented by fittype.
ft = fittype(@(a1,a2,b1,b2,b3,x) 1.21+(a1+a2.*T1).*x+s.*log((b1+b2./T1+b3./T1.^2).*x+1), 'independent', 'x');
Here I created an anonymous function in the call. If s and T1 exist as variables in your works space, they will be encapsulated into the function handle workspace. x is assumed to be the last variable in the calling list as I recall.

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 11 月 6 日
Yes, using the 'problem' name-value pair argument to both fittype and fit.
See the "Create Fit Options and Fit Type Before Fitting" example on the documentation page for the fit function. It specifies n as a problem parameter when the fittype is created then specifies a value for it when the fitting is performed.

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by