Export all fit results from my curve fitting toolbox for multiple fits
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I have a fit session using the cftool - there are multiple fits for different sets of data. Some of the data has 2 or 3 different fits.
My ultimate goal is to compare between the different fits for each set of data point (Say for a particular mesaurment I did 3 different fits and I want to get reduced Chi-squared test in order to chose the best fit).
For that I would want to export all of my fits into the workspace as cfit objects. (I don't need any more data, just the cfit files will suffice).
I can manually use the cftool option and extract every one of them wth Fit>Save to workspace and chose only the checkbox with 'Save fit to MATLAB object named:'
However it seems like a redundent manual work, is there a way to do it automatically.
Here's an example of my fits : each row is a unique data set and for some of them I have fit#1,2 and 3 , these are the different versions.

댓글 수: 0
답변 (1개)
TED MOSBY
2024년 6월 9일
Hi Pavel,
I referred to the MATLAB documentation for the ‘Curve Fitter Tool’ but couldn’t find a way to automate the export process for every fit result which is generated.
Have a look at the documentation for the Curve Fitter tool here:
I can suggest an alternative way to analyse the fits exported but for that you need to first export the fits manually to the workspace. Post that you can write a script that automatically analyse the fits and calculate the reduced chi-squared. A dummy example is shown below:
% Assuming fitresult_lin and fitresult_quad are in the workspace
% And assuming x, y1, and y2 are your data vectors
% Number of parameters for each model:
% For a linear fit (ax + b), m_lin = 2
% For a quadratic fit (ax^2 + bx + c), m_quad = 3
m_lin = 2;
m_quad = 3;
% Calculate residuals for each fit
residuals_lin = y1 - feval(fitresult_lin, x);
residuals_quad = y2 - feval(fitresult_quad, x);
% Assuming equal variance (sigma = 1) for simplicity
sigma = 1;
% Calculate reduced Chi-squared for each fit
chi_squared_red_lin = sum((residuals_lin / sigma).^2) / (length(y1) - m_lin);
chi_squared_red_quad = sum((residuals_quad / sigma).^2) / (length(y2) - m_quad);
% Display the reduced Chi-squared values
fprintf('Reduced Chi-squared (Linear Fit): %f\n', chi_squared_red_lin);
fprintf('Reduced Chi-squared (Quadratic Fit): %f\n', chi_squared_red_quad);
% Comparing the reduced Chi-squared values
if chi_squared_red_lin < chi_squared_red_quad
fprintf('The linear fit is better according to the reduced Chi-squared criterion.\n');
else
fprintf('The quadratic fit is better according to the reduced Chi-squared criterion.\n');
end
As this is just a dummy example, feel free to adjust it according to your data and fits.
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!