Reputation: 713
Suppose I have a best fit equation for a set of data.How can I plot the data with marker and the best fit curve together. I know the command to include a data marker for a curve but this will make the curve pass through all the points if I type something like this
plot(x,polyval(p,x),'kx',x,polyval(p,x))
But this is not what I want since I am plotting a best fit curve. So I would like to know how exactly I can do that. Thanks in advance for all the helps. And between how can I add a polynomial that pass through all the point and the best fit curve as well as the data point with data marker on a same figure.
Upvotes: 1
Views: 488
Reputation: 45752
Where is the data stored? lets say your datapoints are in x
and y
, then make a much finer xi
so something like linspace(min(x), max(x), 1000)
or xi = -100:0.01:100
or whatevers appropriate and then to plot
plot(x, y, 'k*', xi, polyval(p, xi))
Upvotes: 1