How to plot the line of best fit?

5 visualizaciones (últimos 30 días)
Khalil
Khalil el 29 de Abr. de 2013
Comentada: PRANAY CHOWDARY el 9 de Ag. de 2019
%Project Design %Yellow Band Displacemnt=[0 4 8 12 16 20 24 28 32]; Force = [0 .23 .36 .43 .52 .64 .78 .85 .92]; plot(Displacemnt, Force, 'x') title ('Displacement vs Force'); xlabel('Displacement'); ylabel('Force'); grid zoom on
  3 comentarios
Khalil
Khalil el 29 de Abr. de 2013
polyfit(displacement, force, 1)
is not working.
Shashank Prasanna
Shashank Prasanna el 29 de Abr. de 2013
Please format your code using the Code button when you post

Iniciar sesión para comentar.

Respuesta aceptada

Shashank Prasanna
Shashank Prasanna el 29 de Abr. de 2013
What do you mean when you say it is not working? Do you get an error?
D = [0 4 8 12 16 20 24 28 32];
F = [0 .23 .36 .43 .52 .64 .78 .85 .92];
plot(D,F,'.b')
p = polyfit(D,F,1)
f = polyval(p,D);
hold on
plot(D,f,'--r')
Is that something you are looking for?
  5 comentarios
Justin Keener
Justin Keener el 28 de Oct. de 2016
Is there any way to get the approximation returned when the y axis is crossed?
PRANAY CHOWDARY
PRANAY CHOWDARY el 9 de Ag. de 2019
its fine, can you give explanatin

Iniciar sesión para comentar.

Más respuestas (1)

wasif saeed
wasif saeed el 3 de Jun. de 2017
is this possible that we can display slope equation on graph .. i have 251 plot of data by a loop than i draw best fit line from every graph now i need intercept and gradient of each graph on plotting.
  1 comentario
Image Analyst
Image Analyst el 3 de Jun. de 2017
Yes. Use sprintf() to create a string with the equation in it. Then use text() to place that text onto the graph/plot wherever you want it.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by