How to plot an equation qith specific data range?

조회 수: 1 (최근 30일)
Ivan Mich
Ivan Mich 2021년 6월 3일
댓글: Joseph Cheng 2021년 6월 3일
Hello
I have a question about a code. I would like to plot an equation in a plot. But I would like to plot a specific data range of the equation.
E.g X values range from 0 to 100. But i would like to depict ONLY the values between 25-80for equation y.
clc
clear
x=0:5:100
y=3*x+10
y1=4*x+5
plot(x,y)
hold on
plot(x,y1)
could you please help me?

답변 (1개)

Joseph Cheng
Joseph Cheng 2021년 6월 3일
For this you can use the function ylim()
clc
clear
x=0:5:100;
y=3*x+10;
y1=4*x+5;
plot(x,y)
hold on
plot(x,y1)
ylim([25 80])
  댓글 수: 2
Ivan Mich
Ivan Mich 2021년 6월 3일
편집: Ivan Mich 2021년 6월 3일
Thank you but I would like to keep in the same plot the values for the another equation (y1 equation) that ranges between 0 to 100.
I would like to plot
y from 25 to 85 x values and
y1 from 0 to 100 x values
How to make it?
Joseph Cheng
Joseph Cheng 2021년 6월 3일
there are lots of ways but since you are not very clear...................
clc
clear
x=0:5:100;
y=3*x(x>=25&x<=85)+10;
y1=4*x+5;
subplot(211)
plot(x(x>=25&x<=85),y);
hold on
plot(x,y1);
subplot(212)
y=3*x+10;
[ax h1 h2]=plotyy(x,y,x,y1);
ylim(ax(1),[25 85])

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by