Effacer les filtres
Effacer les filtres

how to draw best fit line?

2 vues (au cours des 30 derniers jours)
Amr Hashem
Amr Hashem le 18 Sep 2015
Modifié(e) : Amr Hashem le 19 Sep 2015
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?
  2 commentaires
Image Analyst
Image Analyst le 19 Sep 2015
The line DOES start above the first point.
Amr Hashem
Amr Hashem le 19 Sep 2015
that's what I guess ... thanks

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 19 Sep 2015
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')
  1 commentaire
Amr Hashem
Amr Hashem le 19 Sep 2015
thanks that's close to what i want

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by