Reputation:
I want to graph a fitting curve given vectors with X and Y values, but also some example points, as the vectors are really big (10k+ terms).
Here is an equivalent MWE of the problem I'm facing:
xData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
yData = [1.5, 2.6, 3.7, 4.8, 5.9, 7.0, 8.1, 9.2, 10.3, 11.4];
[pX, pY] = prepareCurveData(xData, yData);
ft = 'linearinterp';
[fitresult, gof] = fit( pX, pY, ft, 'Normalize', 'on' );
gX = xData(1:2:end);
gY = yData(1:2:end);
hold on;
plot(fitresult, pX, pY);
plot(gX, gY, 'k*');
And here is the result of the MWE. As you can see, I can plot the selected points (in black), but the plot(fitresult, pX, pY);
command also plots all the points I used to the curve fitting process (the small, blue ones):
I tried with the plot(fitresult);
command but with that I lose the fitted curve, although the data points are also not plotted.
So, is there a way to plot a fitted curve without its data points?
Upvotes: 1
Views: 3547
Reputation: 944
I edited the code according to the discussion in the comment:
xData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
yData = [1.5, 2.6, 3.7, 4.8, 5.9, 7.0, 8.1, 9.2, 10.3, 11.4];
[pX, pY] = prepareCurveData(xData, yData);
ft = 'linearinterp';
[fitresult, gof] = fit( pX, pY, ft, 'Normalize', 'on' );
% set the scale for a new plot
gX = 1:20;
gY = fitresult(gX);
plot(gX, gY, 'r'); axis tight;
Upvotes: 1