How to use CurveFitting coefficients in the rest of the code?
Show older comments
I have this code:
(t,p)=coordination of out input data
f=fit(t,p,'sin2');
we know it will create this function :
f(t)=a1*sin(b1*t+c1)+a2*sin(b2*t+c2);
and uses it to do the fitting on our input data (t and p);
Now, I have some other set of data(t2), and want to use the same function f(t) and find the answer of f(t2);
How can I call coefficients later in the rest of the code with their value their are assigned to? (after the fitting is done they will have some values)
I have tried coeff = coeffnames(f) but it only prints name of the coefficients.
** f(t2) doesn't work; MATLAB shows error:
Undefined function or variable 'a1'
Accepted Answer
More Answers (1)
Tom Lane
on 9 Aug 2012
1 vote
Although I don't understand what coeffvalues(f) doesn't work, nor why f(t2) doesn't work, nor where the a1 error message comes from, here's another solution nobody mentioned so far.
It is possible to use f.a1 to get at the value of a1, and of course a similar thing for the other parameters.
3 Comments
Peyman
on 10 Aug 2012
Tom Lane
on 10 Aug 2012
You lost me. First, I suggest you try the code from Sean's example under the "more" heading and see what happens. His approach seems to be what you want. I don't see why you would get an error message mentioning a1 if you did that.
Second, I don't understand what is "just wrong." If you fit f to t and then look at f.a1, do you not get the same a1 value that you see in the display of f?
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!