Changing the polynomial coefficients

7 Ansichten (letzte 30 Tage)
barbar
barbar am 15 Jun. 2017
Kommentiert: dpb am 15 Jun. 2017
Hey there, So I have a signal and I fitted a Gaussian model with 8 peaks which results in a total of 24 parameters. I would like change the fitted model coefficients with a small variance to see the change in the fitted model. And I want to this for all of the 24 parameters iteratively in a loop. I know how to extract the coefficient values and names. Fitted model looks like;
a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2) +
a3*exp(-((x-b3)/c3)^2) + a4*exp(-((x-b4)/c4)^2) +
a5*exp(-((x-b5)/c5)^2) + a6*exp(-((x-b6)/c6)^2) +
a7*exp(-((x-b7)/c7)^2) + a8*exp(-((x-b8)/c8)^2)
Just a simple code;
>> [fitresult, gof] = fit( xData, yData, ft, opts );
>> cVals = coeffvalues(fitresult);
>> cNms = coeffnames(fitresult); % Cell
>> fitresult.cNms{1} = 1;
When I try to do this I get the following error;
"The name 'ss' is not a coefficient or a problem parameter. You can only use dot notation to access the coefficients and problem parameters of a cfit or sfit, e.g., 'f.a1'."
So my question is how can I do that without manually entering all the coefficients name like "a1", "a2" and do it automatically?
Thanks in advance,
Baris

Akzeptierte Antwort

dpb
dpb am 15 Jun. 2017
Bearbeitet: dpb am 15 Jun. 2017
Syntax problem--analgously to structure dynamic field names, the string after the dot is interpreted as literal character string, not as a variable. To use dynamic field name, surround the variable by normal parens ().
fitresult.(cNms{1}) = 1;
will succeed.
AMENDMENT TO PREVIOUS:
Before it dawned on me what/where the problem lay I had come across cfit just a day or so prior to this and recalled it having the facility.
One peculiarity with it is that it MUST have a complete list for every parameter in the model; you can't use named parameters and you can't leave any out and and you also can't use an array to hold them (must have comma-separated list). Thus, while it's doable, the above will turn out to be more suitable for "one-at-atime" modifications.
See
doc cfit
It will let you modify coefficients of a model without doing a fit (the only purpose for user calling it). I've not had need to do it but seems it should be just what you're looking for here.
  2 Kommentare
barbar
barbar am 15 Jun. 2017
Thanks. I thought that I tried to put coeffNames between parens but obviously I didn't.
dpb
dpb am 15 Jun. 2017
Who knows what we try or think we have tried when debugging/trying new things...??? :) Glad it dawned on me what the issue was; just one of those "Aha!" flashes out of the blue when it did; I've no klew as to why...wasn't doing anything even closely related at the time.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by