Hello
If i had the following
clear
clc
x=0:10
y=-2*x+6
y1=3*x
plot(x,y)
hold on
plot(x,y1)
how would i just plot the graph with the limits being the x and y intercept

댓글 수: 7

Geoff Hayes
Geoff Hayes 2020년 4월 25일
Elliot - plaese clarify what you mean by with the limits being the x and y intercept. What do you want the minimum and maximum limits for the x and y axes?
Elliott Cameron
Elliott Cameron 2020년 4월 25일
i want the plot to show no lower than where y1 intercepts the x axis and no higher than where y1 intercepts the y axis sorry i realise that wasnt very clear
Star Strider
Star Strider 2020년 4월 25일
Note that ‘y1’ intercepts both the x and y axes at (0,0).
Elliott Cameron
Elliott Cameron 2020년 4월 25일
sorry y and y1 are the wrong way round
Tommy
Tommy 2020년 4월 25일
You can solve for the intercepts using the equation for y1 and update the axes limits accordingly:
clear
clc
x=0:10;
y1=-2*x+6;
y=3*x;
plot(x,y)
hold on
plot(x,y1)
yint = 6; % -2*0 + 6 => 6
xint = 3; % (0 - 6)/(-2) => 3
ax = gca;
ax.XLim(2) = xint;
ax.YLim(2) = yint;
dpb
dpb 2020년 4월 25일
@Tommy...you have/are developing my habit of putting Answers in Comments... :)
Tommy
Tommy 2020년 4월 25일
Ah! Yes I agree... I do often question if I really understand what's being asked, and whether my "answer" is a full answer, but too often I default to the comment section

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

 채택된 답변

Tommy
Tommy 2020년 4월 25일

0 개 추천

You can solve for the intercepts using the equation for y1 and update the axes limits accordingly:
clear
clc
x=0:10;
y1=-2*x+6;
y=3*x;
plot(x,y)
hold on
plot(x,y1)
yint = 6; % -2*0 + 6 => 6
xint = 3; % (0 - 6)/(-2) => 3
ax = gca;
ax.XLim(2) = xint;
ax.YLim(2) = yint;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2020년 4월 25일

댓글:

2020년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by