Plotting a straight line y=c

조회 수: 13 (최근 30일)
Tom Fry
Tom Fry 2018년 10월 14일
댓글: Star Strider 2018년 10월 14일
I've searched forums but surprisingly can't find anything that seems to work how I would like.
The following is my code:
if true
% m=50; %kg
k=100; %kN/m
M=200; %kg
g=9.81; %ms-1
t = 0:0.01:10; %s
F0 = M*g;
omega0 = sqrt(k/m);
x = (F0/k)*(1-cos(omega0*t));
c1 = (M*g)/k;
plot(t,x);
hold on;
plot(t, c1);
end
All I wish to do is plot x(t) then plot y=c1 on top. The first seems to plot but the second doesn't appear.
I'm relatively new to MatLab so any advise would help!
Thanks in advance.

채택된 답변

Star Strider
Star Strider 2018년 10월 14일
편집: Star Strider 2018년 10월 14일
The easiest way to plot a horizontal line at ‘c1’ is simply:
plot(xlim, c1*[1 1]);
The xlim call returns the current value of the x-axis limits as a (1x2) vector. All you then need to do is to supply a (1x2) vector at the value of ‘c1’, and it will plot the line.
  댓글 수: 2
Tom Fry
Tom Fry 2018년 10월 14일
Awesome, thank you!!
Star Strider
Star Strider 2018년 10월 14일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by