How can I graph several points from a table and extrapolate a curve?

2 views (last 30 days)
I'm somewhat new to MATLAB, although I used it in school. I have a table of x and y-values, and want to plot the points on a graph and then extrapolate a linear curve. Can someone help explain how to do this? I am used to graphing with equations, this is sort of the opposite way around.

Accepted Answer

dpb
dpb on 9 Dec 2013
Well, poly[fit|val] are "all in Matlab"...
dat=[1500,200; 2500,259; 4530,1980];
plot(dat(:,1),dat(:,2))
p=polyfit(dat(:,1),dat(:,2),1);
yhat=polyval(p,[1000 5000]);
hold on
plot([1000 5000],yhat)

More Answers (1)

dpb
dpb on 9 Dec 2013
A) doc plot
B) doc polyfit % and polyval
  1 Comment
Stephen
Stephen on 9 Dec 2013
Thank you. If I'm looking more to do it all in matlab, then, say I'm starting at a data range like
x=1000:10:5000; y=0:.5:2000;
and I want to plot several points, say (1500,200) (2500,259) and (4530,1980) and then apply the polyfit % and polyval functions. How would I accomplish something like that?

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots 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!