MATLAB: Interpolating near discontinuties

jump discontinuityplotting

Hello Everyone,
I have a very itchy problem.
I am trying to plot the following function which has jump discontinuities.
x=0:0.0001:2;
y=5*x;
x1=2:0.0001:3;
y1=5*(x1)+1;
plot(x,y,x1,y1);
This is giving a plot which has a jump discontinuity at 2. I want the matlab to join discontinuity by a line.
Thanks in advance.
Thanks & Regards,
Arun Sahu

Best Answer

f = @(x)5*x + (x > 2)
plot(0:1e-4:3,f(0:1e-4:3))
OR:
x=0:0.0001:2;
y=5*x;
x1=2:0.0001:3;
y1=5*(x1)+1;
plot([x,x1],[y,y1]);