Changing the polynomial coefficients
조회 수: 10 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
dpb
2017년 6월 15일
편집: dpb
2017년 6월 15일
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
dpb
2017년 6월 15일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!