It's not a symbolic object, nor a function--it's a cfit object. It has associated methods and the default method is to evaluate the function with the input arguments so it does superficially look like a function. In this case, however, just because it looks and quacks like, it isn't a duck. :)
The simplest way to output to a file for later reuse is
This has the distinct advantage that you regain the entire functionality of the object on recall instead of just pieces...
>> p=fit([1:10].',rand(10,1),'poly1')
p =
Linear model Poly1:
ans(x) = p1*x + p2
Coefficients (with 95
p1 = 0.003135 (-0.06473, 0.071)
p2 = 0.4877 (0.06662, 0.9088)
>> whos p
Name Size Bytes Class Attributes
p 1x1 708 cfit
>> save pfit p
>> whos -file pfit
Name Size Bytes Class Attributes
p 1x1 708 cfit
>> clear p
>> load pfit
>> p
p =
Linear model Poly1:
p(x) = p1*x + p2
Coefficients (with 95
p1 = 0.003135 (-0.06473, 0.071)
p2 = 0.4877 (0.06662, 0.9088)
>>
BTW, need to read the documentation on using the fit objects carefully...and the tab completion at the command line is very helpful in prompting for methods and the error messages if try wrong things are generally good in leading to the right answer. eg, for the above to retrieve coefficients, use:
>> p.coeffvalues
Error using cfit/subsref (line 18)
The name 'coeffvalues' 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.p1'.
For the current fit, you can access these properties: p1, p2
You can get coefficient names and values either by name, e.g., p1 = f.p1, or by using the coeffnames or coeffvalues functions, e.g., names =
coeffnames(f).
To use methods, use functional notation instead, e.g., plot(f).
>> coeffvalues(p)
ans =
0.0031 0.4877
>>
So, again, you don't need loops; you could export the array of coefficients, but by doing so you'll have them but have lost the facility to use them later unless you code to evaluate the function explicitly.
Best Answer