How can I get my x-and y-values of my polynomial fit into a matrix?
Show older comments
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
on 8 Jun 2014
Answers (2)
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
on 8 Jun 2014
dpb
on 8 Jun 2014
I might accept the 5th order but I pretty much stand by the comment on a 9th-order poly. Would have to see the raw data and results to really comment in depth.
I'd still think a spline would likely do the same job with less of such issues if there isn't any analytic model on which to base the correlation.
Stian
on 8 Jun 2014
Stian
on 8 Jun 2014
Stian
on 8 Jun 2014
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 Linear and Nonlinear Regression 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!