why the plot curve is not smooth as the fitted curve

5 次查看(过去 30 天)
I fitted a Quadratic curve, such as
f = fit(x,y, 'ploy2');
If I plot the fitting curve plot(f, x, y)
plot(f, x, y);
the curve is smooth, but if I plot the curve like this
yy = f.p1 * x.^2 + f.p2 * x + f.p3;
plot(x, yy);
the plotted curve is not as smooth as the curve plotted using the syntax plot(f, x, y). What's the difference between this two function callings?

回答(1 个)

dpb
dpb 2016-12-28
编辑:dpb 2016-12-28
The supplied plot function that is fit -object aware uses an internally-determined number of points to evaluate the function that are more than those in the data set itself--I just did a test here--for a sample dataset of length 15 where I fit y=x.^2+rand(size(x))*10; for a vector x=[1:15];
>> f=fit(x',y','poly2'); % fit the above quad+noise
>> h=plot(f,x,y) % use the builtin plot; return line handles
h =
633.0012
634.0002
>> tmp=get(h(1),'xdata'); % get the data for the raw data...
>> length(tmp) % and show how many points were there--
ans =
15
>> tmp=get(h(2),'xdata'); % ditto for the curve of the fit...
>> length(tmp)
ans =
1013
>>
As you can see, it computed the fit at over 1000 points internally to draw a smooth curve whereas your manual plot is just "connecting the dots" between the fitted points since you only evaluated at the input values.

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by