1
votes

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):

Output of provided MWE

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?

1
what about just using plot(fitresult, gX, gY, 'k*');. If you look at the documentation of plot, you are plotting 2 different information, (fitresult) and (gX, gY, 'k*')R.Falque
@R.Falque Forget what I said -- that worked! Thank you so much! Just put this as an answer and I'll vote it up! :)user5117901
@R.Falque To answer your other question, I tried with plot(fitresult); but it shows me no fitting curve output -- but also no errors.user5117901
I think you should just create a new figure beforehand. Adding the points just set the scale of your plot btw ;)R.Falque
@R.Falque That's a good hack! Just plot some garbage points and set the scale so the graph won't show them! XPuser5117901

1 Answers

1
votes

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;