How can I change opts.StartPoint for every loop iteration for the predefined points used by the curve fitting tool?

7 ビュー (過去 30 日間)
Dear community,
Using the curve fitting tool, I have generated the code to fit a curve using specific x and y values. However, I want to automate this process for n curves with different x and y values (with a loop). The problem is that the generated code uses those particular to my first curve as starting points.
In addition, if I leave the starting point unspecified, some estimates give an error. Is there a way to change the starting values at each iteration so that the fit on that iteration is based on the predefined starting points used by the curve fitting tool? I found a similar question in the forum (https://fr.mathworks.com/matlabcentral/answers/578068-how-can-i-change-opts-startpoint-for-a-custom-equation-at-every-loop-iteration). However, the user's initial points matrix would have to be defined manually, and I am looking for the same points that the tool generates, i.e., not to write anything manually. Is this possible?
So far my code is as follows:
ft_left= fittype( 'power2' );
fit_curve=cell(1,length(Arrays_jan));
for k = 1:length(Arrays_jan)
fit_curve{k}= fit(x{k},y{k},ft_left);
end
Thank you very much!

採用された回答

Matt J
Matt J 2021 年 12 月 16 日
編集済み: Matt J 2021 年 12 月 16 日
However, the user's initial points matrix would have to be defined manually, and I am looking for the same points that the tool generates, i.e., not to write anything manually
That is what is happening in the code that you've posted already. When you don't specify a starting point, fit() will automatically generate one.
  2 件のコメント
Angelavtc
Angelavtc 2021 年 12 月 16 日
@Matt J thanks for the answer. Yes, but this is not the same starting point that the tool uses despite specifying fittype( 'power2' ). Does it has to do with the explanation you gave me in the question ?https://fr.mathworks.com/matlabcentral/answers/1608835-why-is-it-that-if-i-adjust-a-curve-with-the-curve-fitting-tool-it-does-not-give-me-the-same-results?s_tid=srchtitle. Because in my iterazion I am specifying that it is a power2 fit, but still it is not the same starting point.
I am interested in automating the process because estimating each curve with the tool "curve fitting tool" is impossible (I want to estimate 70 thousand curves).
Matt J
Matt J 2021 年 12 月 16 日
but this is not the same starting point that the tool uses despite specifying fittype( 'power2' )
Yes, it is the same.The cftool app is just a wrapper for fit().
If curves in adjacent loop iterations are expected to be similar, it can be helpful to choose the previous solution as the start point:
ft_left= fittype( 'power2' );
fit_curve=cell(1,length(Arrays_jan));
NameValue={};
for k = 1:length(Arrays_jan)
fit_curve{k}= fit(x{k},y{k},ft_left,NameValue{:});
NameValue={'StartPoint',coeffvalues(fit_curve{k})};
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFit Postprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by