% Testregress.m Feb. 2005 L Braile % Test and plot the regress m-file for calculating the % least squares straight line function with sample data x = [1 2 3 4 5 6 7 8 9]; y = [1.5 1.8 2.0 3.6 4.1 6.8 6.4 4.0 9.4]; npts = length(x); X = [ones(npts,1) x']; % set up the least squares coefficient matrix figure [b,bint,r,rint,stats] = regress(y',X,0.05) % Calculate and print % least squares line and statistics. The data from regress can also % be used to make a plot of the residuals rcoplot(r,rint); % plot the data and least squares line figure plot(x,y,'ro','markersize',12,'linewidth',3) % Plot the data set(gca,'fontsize',16,'linewidth',2) hold on xlabel('x-values','fontsize',16) ylabel('y-values','fontsize',16) title('Plot of sample data and least squares straight line fit','fontsize',16) yt = feval('sline',x,b(1),b(2)); % Calculate the fitted line plot(x,yt,'k-','linewidth',3) % Plot the fitted line axis([0 10 0 10]); % Set axis limits for plot hold off