Borrar filtros
Borrar filtros

how to draw best fit line?

2 visualizaciones (últimos 30 días)
Amr Hashem
Amr Hashem el 18 de Sept. de 2015
Editada: Amr Hashem el 19 de Sept. de 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 comentarios
Image Analyst
Image Analyst el 19 de Sept. de 2015
The line DOES start above the first point.
Amr Hashem
Amr Hashem el 19 de Sept. de 2015
that's what I guess ... thanks

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Sept. de 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 comentario
Amr Hashem
Amr Hashem el 19 de Sept. de 2015
thanks that's close to what i want

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by