% set values for x and y, the raw data x = [1;2;3;4;5]; y = [2.1;3.8;6.0;9.;11.1]; % set values for the error bars for each point e = [0.7,0.3,0.5,0.2,0.3]; % fit a first order polynomial (i.e. straight line) to the data, % "p" has the two coefficients for the straight line. p=polyfit(x,y,1); % generate a set of yy values for each x using the curve fit. yy=polyval(p,x); % plot the results ("hold on" puts the output of "errorbar" and "plot" % onto the same figure) hold on; errorbar(x,y,e,'o') plot(x,yy,'r') xlabel('x_o (m)') ylabel('y_o (m)')