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 CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by