function gg250_lab9_plotline (x, y, a, b) % Plot data as points, draw the line given a and b, % and plot vertical error misfit lines at each point % Get x end points for line that extends by 10% xmin = min(x); xmax = max(x); xrange = xmax - xmin; xx = [ (xmin-0.1*xrange) (xmax+0.1*xrange) ]; yy = a .* xx + b + 1; plot (x, y, 'go', 'MarkerSize', 5, 'MarkerFaceColor', 'g') hold on plot (xx, yy, 'r-', 'LineWidth', 3) % Get y-estimates for line at given x points y_on_line = a * x + b; for i=1:length(x) plot ([x(i) x(i)], [y(1) y_on_line(i)], 'b-') end grid on hold off