Is it possible to fit multiple data sets in the same 'fit'??
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
So my dilema is that the code below runs the first fit until 'DiffMinChange' is satisfied and then it moves to the second fit. I want to know if it is possible to operate both fits and then check 'DiffMinChange'. I assume I will need a while statement, but I am not sure how the 'fit' function will react. Any help is appreciated!
% Define first fittype
ft1 = fittype('FitLT1(xdata1, mtrlmod, cgs, cds, cgd0, coxd, vtd, vtdtco, fc, m, wb, nb, a, agd, thetal, thetalr, thetah, thetaltexp, thetahtexp, kfl, kfh, kpl, kph, kflr, kplr, kfltexp, kfhtexp, kpltexp, kphtexp, vtl, vth, vtlr, vtltco, vthtco, vbigd, pvfl, pvfh, slmin, id0, vb, rs, rd, rdr, rdvd, rdvg11, rdvg12, rdtemp1, rdtemp2, rdvdtemp1, rdvdtemp2, rdiode, is_body, kvsg1, kvsg2, nd, temperature, tnom, vk1, vk2, tt, tau, multiplier, p_delta, thetalrtexp, kplrtexp, rdrtemp1, rdrtemp2, rdiodetemp1, rdiodetemp2, vtlrtco, vk1tco, vk2tco, ndtco, kvsg1texp, kvsg2texp)',...
'independent', {'xdata1'},...
'dependent', {'ydata1'},...
'problem', optInfo1.const_vars,...
'coefficients', optInfo1.opt_params);
% Call first fitting function and save the optimized parameter values,
% measurements on goodness of fit, and optimization data.
[fit_result1, gof1, fit_info1] = fit(xdata1, ydata1, ft1, 'problem', optInfo1.const_vals,...
'Lower', optInfo1.lower_bound, 'Upper', optInfo1.upper_bound, 'DiffMinChange', optInfo1.min_diff);
% Define second fittype
ft2 = fittype('FitLT2(xdata2, mtrlmod, cgs, cds, cgd0, coxd, vtd, vtdtco, fc, m, wb, nb, a, agd, thetal, thetalr, thetah, thetaltexp, thetahtexp, kfl, kfh, kpl, kph, kflr, kplr, kfltexp, kfhtexp, kpltexp, kphtexp, vtl, vth, vtlr, vtltco, vthtco, vbigd, pvfl, pvfh, slmin, id0, vb, rs, rd, rdr, rdvd, rdvg11, rdvg12, rdtemp1, rdtemp2, rdvdtemp1, rdvdtemp2, rdiode, is_body, kvsg1, kvsg2, nd, temperature, tnom, vk1, vk2, tt, tau, multiplier, p_delta, thetalrtexp, kplrtexp, rdrtemp1, rdrtemp2, rdiodetemp1, rdiodetemp2, vtlrtco, vk1tco, vk2tco, ndtco, kvsg1texp, kvsg2texp)',...
'independent', {'xdata2'},...
'dependent', {'ydata2'},...
'problem', optInfo2.const_vars,...
'coefficients', optInfo2.opt_params);
% Call second fitting function and save the optimized parameter values,
% measurements on goodness of fit, and optimization data.
[fit_result2, gof2, fit_info2] = fit(xdata2, ydata2, ft2, 'problem', optInfo2.const_vals,...
'Lower', optInfo2.lower_bound, 'Upper', optInfo2.upper_bound, 'DiffMinChange', optInfo2.min_diff);
0 Kommentare
Antworten (1)
TED MOSBY
am 4 Apr. 2024
Hi Steven,
I understand that you want to calculate the value of the variable “diffMinChange” after fitting both the datasets.
You can use the while loop implementation as shown below:
% Set initial values for loop control
diffMinChangeCondition1 = false;
diffMinChangeCondition2 = false;
% Define first fittype
ft1 = fittype(...); % Your first fittype definition
% Define second fittype
ft2 = fittype(...); % Your second fittype definition
% Loop until 'DiffMinChange' is satisfied for both fits
while ~ (diffMinChangeCondition1 && diffMinChangeCondition2)
% Call first fitting function and save the optimized parameter values,
[fit_result1, gof1, fit_info1] = fit(xdata1, ydata1, ft1, 'problem', optInfo1.const_vals,...
'Lower', optInfo1.lower_bound, 'Upper', optInfo1.upper_bound, 'DiffMinChange', optInfo1.min_diff);
% Call second fitting function and save the optimized parameter values,
[fit_result2, gof2, fit_info2] = fit(xdata2, ydata2, ft2, 'problem', optInfo2.const_vals,...
'Lower', optInfo2.lower_bound, 'Upper', optInfo2.upper_bound, 'DiffMinChange', optInfo2.min_diff);
% Check if DiffMinChange condition is satisfied for both fits
diffMinChangeCondition1 = fit_info1.DiffMinChange < optInfo1.min_diff;
diffMinChangeCondition2 = fit_info2.DiffMinChange < optInfo2.min_diff;
end
This is one of the ways of doing it. Feel free to modify the code according to your needs. Hope it helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!