How to plot the line of best fit?

조회 수: 5 (최근 30일)
Khalil
Khalil 2013년 4월 29일
댓글: PRANAY CHOWDARY 2019년 8월 9일
%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