How to plot the line of best fit?

5 次查看(过去 30 天)
%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 个评论
Khalil
Khalil 2013-4-29
polyfit(displacement, force, 1)
is not working.
Shashank Prasanna
Shashank Prasanna 2013-4-29
Please format your code using the Code button when you post

请先登录,再进行评论。

采纳的回答

Shashank Prasanna
Shashank Prasanna 2013-4-29
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 个评论
Justin Keener
Justin Keener 2016-10-28
Is there any way to get the approximation returned when the y axis is crossed?
PRANAY CHOWDARY
PRANAY CHOWDARY 2019-8-9
its fine, can you give explanatin

请先登录,再进行评论。

更多回答(1 个)

wasif saeed
wasif saeed 2017-6-3
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 个评论
Image Analyst
Image Analyst 2017-6-3
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by