How can I change opts.StartPoint for a custom equation at every loop iteration?

8 ビュー (過去 30 日間)
pinar
pinar 2020 年 8 月 11 日
編集済み: Matt J 2021 年 12 月 16 日
Hello,
I have generated a code to fit a Gaussian CDF to the data points of each participant. Since I generated the code by using only one participant's data as a sample, opts.StartPoint was based on this one participant's data points. But the fits were not very good when I did it like this.
So what I want to do is to change opts.StartPoint at each iteration so that the fit on that iteration is based on the start points selected for that participant.
Below is how I have written the start points initially.
```
% Set up fittype and options.
ft = fittype( 'a*(.5*(1+erf((x-m)/(s*sqrt(2)))))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.71149061180612 0.231594386708524 0.488897743920167];
opts.MaxFunEvals = 1000;
```
Thank you!

回答 (1 件)

Uday Pradhan
Uday Pradhan 2020 年 8 月 14 日
Hi Pinar,
It is my understanding that you would like to define custom starting points for your curve - fitting model for different participants. To do this, we can create an n by 3 matrix startPts (n being the number of participants) containing the parameters a, m and s in that order (i.e. the i - th row of startPts is the start point for the i - th participant). Then, we can use a loop to create n different fit objects which have different starting points based on the vectors extracted from startPts. I have a code snippet below that you may find useful.
%startPts is the n - by - 3 matrix containing the start points for each of the 'n' participants;
ft = fittype( 'a*(.5*(1+erf((x-m)/(s*sqrt(2)))))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.MaxFunEvals = 1000;
s = cell(n,1); %store the n fitobjects for plotting
for i = 1:n
opts.StartPoint = startPts(i,:);
s{i} = fit(x,y,ft,opts);
end
  3 件のコメント
Mirjam Studler
Mirjam Studler 2021 年 11 月 24 日
編集済み: Mirjam Studler 2021 年 11 月 24 日
Did you manage to find a solution to generate opts.StartPoint automatically in the code? I actually face the same problem.
Matt J
Matt J 2021 年 12 月 16 日
編集済み: Matt J 2021 年 12 月 16 日
Angelavtc's comment moved here:
Dear @Uday Pradhan your answer is very useful, but your code makes the matrix "startPts" a predefined matrix by the user. Is there a way to make this matrix contain the starting point used by the curve fitting tool?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by