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

3 visualizaciones (últimos 30 días)
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!

Respuestas (1)

Uday Pradhan
Uday Pradhan el 14 de Ag. de 2020
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 comentarios
Mirjam Studler
Mirjam Studler el 24 de Nov. de 2021
Editada: Mirjam Studler el 24 de Nov. de 2021
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 el 16 de Dic. de 2021
Editada: Matt J el 16 de Dic. de 2021
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by