MATLAB: Changing the polynomial coefficients

curve fitting

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

Best Answer

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.