MATLAB: Plotting graphs in matlab

graph

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

Best Answer

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;