How to plot two different scripts on one graph

조회 수: 9 (최근 30일)
Sydney
Sydney 2022년 9월 16일
댓글: Star Strider 2022년 9월 16일
I need to plot a graph for one variable and then again for an increase in that variable but need to display them on the same plot. How do I do this? Thank you

답변 (2개)

Star Strider
Star Strider 2022년 9월 16일
Use the hold funciton —
t = linspace(0, 100, 1001)*0.1;
s1 = sin(2*pi*t);
s2 = s1*1.5;
figure
plot(t, s1, 'DisplayName','s_1')
hold on
plot(t, s2, 'DisplayName','s_2')
hold off
grid
xlabel('Time')
ylabel('Amplitude')
legend('Location','best')
.
  댓글 수: 2
Sydney
Sydney 2022년 9월 16일
So do i run the code for Ma=0. Then in the command window write hold on. Then run again for Ma=2 and it will work? Thank you.
Star Strider
Star Strider 2022년 9월 16일
So do i run the code for Ma=0. Then in the command window write hold on. Then run again for Ma=2 and it will work?
I have no idea what you’re referring to (and there is not enough information visible in the image for me to infer anything). This should be done in a script, similar to what I wrote in my answer, since I have no idea what you’re doing in the Command Window. However if both have compatible independent and dependent variable vectors, or both can be plotted against the same independent variable vector, then, yes, in an appropriate script.

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


TSE SHAO CHANG
TSE SHAO CHANG 2022년 9월 16일
Is the following what you are looking for?
t = linspace(0,20,100);
x1 = sin(t);
x2 = cos(t);
figure;
plot(t, x1)
hold on
plot(t ,x2)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by