how to get fit coefficients and the file name ?

조회 수: 1 (최근 30일)
dareen
dareen 2024년 6월 24일
댓글: dareen 2024년 6월 27일
there is a particular feature that i needed a couple of times now but i am failing at finding something to implement it
inductor_files = {
'2_2.csv', '2_5_long.csv', '8_8.csv', '11_9.csv', '14_2.csv', ...
'24_8.csv', '27_0.csv', '29_3.csv', '31_5.csv', '33_2.csv', ...
'33_7.csv', '34_3.csv', '34_8.csv', '36_6.csv', '37_7.csv', ...
'42_2.csv', '44_3.csv', '49_4.csv'
};
% Loop through each inductor file
for i = 1:length(inductor_files)
% Read the data from the CSV file
data = readmatrix(inductor_files{i});
% Plot the data
figure;
% plot(data(:,4), data(:,5));
cftool(data(:,10), data(:,11));
end
if you look at the following code for now what it simply does is use cftool to graph 18 graphs i keep doing the fit on them manually through the cftool window and same for extracting the coffecients ,
the more files i have the more time consuming this is , if i want to write something along the following lines
cftool(data(:,10), data(:,11)) fit (sum of sine ,order 1 , for all )
so when the cftool opens i have the default fiting here be sum of sine
second if i want the coffecients that define amplitude of the sin genearted to be saved in order of each run so i know what file are they extracted in how can i access the coffecient of intrest and save the data it carries
  댓글 수: 2
dareen
dareen 2024년 6월 24일
편집: dareen 2024년 6월 24일
it seems i will do this maually for around 50 files this time and i know it is totally implementable ,
John D'Errico
John D'Errico 2024년 6월 24일
Why do you think you need to use cftool? You don't. cftool is merely a gui interface for the curve fitting toolbox. But you don't need the gui interface at all. In fact, you really don't want it, since you are doing the same fits for each set of data. Instead, learn how to use tools like fittype and fit.
You can still plot the fit if you want, since plot works on what fit returns. And since fit returns an object that contains the fitted model itself, that gives you the coefficients you need.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2024년 6월 24일
You can perform the fitting once in the Curve Fitting app then generate MATLAB code from that interactive fit that you can later run with a new data set to fit it in the same manner. Then you could evaluate the fits at specific points.
Alternately you could follow the workflow given on this documentation page to programmatically fit your data without having to open the Curve Fitting app and interactively perform the fit.
  댓글 수: 2
dareen
dareen 2024년 6월 27일
thank you exactly what i needed a set of tools and resourses to study
dareen
dareen 2024년 6월 27일
took me a while to read and apply but worked well

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by