Clear Filters
Clear Filters

How can I get my x-and y-values of my polynomial fit into a matrix?

14 views (last 30 days)
Hi, I have made a polynomial fit to my data from the laboratory, but can't find out how to get this polynomial fit into a matrix for further use and extraction into Excel. I can easily plot it, but thats is strait from the fit-function as seen in my script:
RowTid14 = 4385; %Chosen timevalue at start of last cycle 4385
RowX14 = RowTid14;
RowY14 = RowX14;
T14y=csvread('Test14.txt', RowY14, 1);
T14x=csvread('Test14.txt', RowX14, 2);
T14tid=csvread('Test14.txt', RowTid14, 0);
enomtest14=T14x(:,1)/z6;
%Data
x = 0.05+log(1+enomtest14);
y = (T14y(:,1)/Az6).*(1+enomtest14);
%Polynomial fit of my data
Fit14 = fit(x,y,'poly9');
%Plot of my data and my fit
plot(Fit14)
hold on
plot(x,y)
xlabel('True Strain','Fontsize',10)
ylabel('True Stress [N/mm^2]','Fontsize',10)
set(gca,'XDir','reverse')
set(gca,'YDir','reverse')
xlim([-0.52 0])
ylim([-7 0.1])
legend('Fit','Data','location','North')
So what i would like, is help to get the x- and y-values for the red line into a matrix [1020x2].
Thanks in advance for all answers.
-Stian
  1 Comment
Stian
Stian on 8 Jun 2014
And here is the polynomial function, if it is needed:
Linear model Poly9:
Fit14(x) = p1*x^9 + p2*x^8 + p3*x^7 + p4*x^6 +
p5*x^5 + p6*x^4 + p7*x^3 + p8*x^2 + p9*x + p10
Coefficients (with 95% confidence bounds):
p1 = 6.475e+05 (-8.204e+05, 2.115e+06)
p2 = 1.286e+06 (-1.674e+06, 4.247e+06)
p3 = 1.044e+06 (-1.389e+06, 3.477e+06)
p4 = 4.387e+05 (-6.032e+05, 1.481e+06)
p5 = 9.773e+04 (-1.478e+05, 3.433e+05)
p6 = 9523 (-2.093e+04, 3.998e+04)
p7 = -173.7 (-1854, 1507)
p8 = -95.25 (-172.1, -18.43)
p9 = 3.246 (-1.413, 7.905)
p10 = 0.004628 (-0.1033, 0.1125)

Sign in to comment.

Answers (2)

dpb
dpb on 8 Jun 2014
The bigger problem is the choice of a fitting polynomial of order 9 is giving (mostly) nonsense.
Just as an example, look at the p6 and p7 terms--
>> p6 = 9523; e6=[-2.093e+04, 3.998e+04];
>> p7 = -173.7; e7=[-1854, 1507];
>> [p6-e6]/p6*100 % per cent est error in coefficient
ans =
319.78 -319.83
>> [p7-e7]/p7*100
ans =
-967.36 967.59
>>
That's 300% and 1000% error estimated; the value of the coefficients is worthless.
Have you plotted the data itself FIRST; surely there's some better model that has some physical basis, no matter how removed. If it's simply for interpolation or correlation, use a smoothing spline or the like.
Anyway, that problem aside, the methods for a fit object are documented under the heading of Fit Postprocessing but you've got more work to do before you're ready for them.
  5 Comments
Stian
Stian on 8 Jun 2014
But back to the original question: Do you know how I can get those x- and y-values from that fit-curve into a matrix 1020 rows 2 columns?

Sign in to comment.


dpb
dpb on 9 Jun 2014
...how I can get those x- and y-values from that fit-curve into a matrix 1020 rows 2 columns
You've already got x and y; if you want an array just concatenate them (but note that you may not actually need to create another explicit array depending on your end objective).
xy=[x y];
I thought you were speaking of evaluating the fit or some other result which is in the methods for the fit object documented under "postprocessing".
To finish up our previous discussion, I did look at the fit and run your script last night but got too enamored by the rain event here to get back (we're in D4 "Exceptional" drought conditions and are in our third year so anything that aids that is really big news at the moment). Anyway, iff the only purpose of the fit were to evaluate the poly between the two end conditions, I'd agree you can get by w/ either but if it were me I'd go with the 5th instead of 9th just on the principle of parsimony.

Categories

Find more on Polynomials 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!