Hi, I'm trying to fit a collection of data points to a line, but when I call polyfit, it returns a completely unexpected result for both the slope and the y-intercept. I checked the help section and documentation but I don't know what I'm doing wrong…
I even tried finding the fit for a line, and it failed too. This is the code I'm using:
t = linspace(0,2); x = 2*t+3;[p,S,mu] = polyfit(t,x,1);polyval(p,t,S);plot(t,x)hold on[y,delta] = polyval(p,t,S);errorbar(t,y,delta)legend('line','fit')
And this is the plot I get:
Please let me know if I'm doing anything incorrectly.
Thanks in advance.
Best Answer