1.After I use the function fit like this,
p=fit([x,y],z,g,op);
I get a result p, data type is sfit.
I read the document, and found out that p can be invoked just like a function:
z=p(x,y);
But when I tried to write this function to a file like this,
matlabFunction(p,'file','p');
I received an error saying that matlabFunction cannot write this function to a file.
2. So I came up with another way.
I noticed the result is structured as
General model: val(x,y) = p9.*x.^3+p8.*x.^2.*y+p7.*x.*y.^2+p6.*y.^3 +p5.*x.^2+p4.*x.*y+p3.*y.^2+p2.*x+p1.*y+p0 Coefficients (with 95% confidence bounds):
p1 = -0.002069 (-0.002113, -0.002025) p2 = -0.003244 (-0.003276, -0.003213) p3 = 0.03401 (0.03396, 0.03405) p4 = 0.0003719 (0.000349, 0.0003948) p5 = -0.01642 (-0.01644, -0.0164) p6 = -0.0005034 (-0.0005421, -0.0004647) p7 = 0.0002566 (0.0002348, 0.0002784) p8 = 0.004362 (0.004347, 0.004376) p9 = 0.0002652 (0.0002521, 0.0002784) p0 = -0.01646 (-0.01649, -0.01643)
I thought it's ok that I export the coefficients in this way:
coef(1)=p.p1; coef(2)=p.p2;
But in my project, when the number of coefficients reaches larger, and I want to do this with a for loop:
for i=1:n coef(i)=p.p(i); end
I found that matlab doesn't support the syntax p.p(i)!
So how can I export the result of the function fit to a file anyway? I'm feeling a little upset.
Best Answer