MATLAB: How to draw best fit line

adjust fitted linebest fit line

I use :
F=[200000;250000;270000];
G=[8000;12000;13000];
figure
plot(F, G, 'go')
hold on;
coeffsss = polyfit(F, G, 1);
fittedXxx = linspace(min(F), max(F), 200);
fittedYyy = polyval(coeffsss, fittedXxx);
plot(fittedXxx, fittedYyy, 'r-', 'LineWidth', 1);
but the line was not completed
I want the line to start from the the beginning/above of the first point.
how I can do this?

Best Answer

Perhaps you want to go from xlim(1) to xlim(2):
clear; % Erase all existing variables. Or clearvars if you want.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
F=[264099;279945;297302];
G=[9723;14952;14462];
plot(F, G, 'bo', 'LineWidth', 2, 'MarkerSize', 10)
xlabel('F', 'FontSize', fontSize);
ylabel('G', 'FontSize', fontSize);
grid on;
hold on;
coefficients = polyfit(F, G, 1);
xLimits = xlim
fittedX = linspace(xLimits(1), xLimits(2), 200);
fittedY = polyval(coefficients, fittedX);
plot(fittedX, fittedY, 'r-', 'LineWidth', 3);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')