MATLAB: Graph plotting HELP NEEDED

graphMATLAB

How can I plot this graph in matlab?
I have trouble plotting this one

Best Answer

Try this:
x = linspace(-1, 3);
y = 2*((x >= 0) & (x < 1)) + 1*((x >= 1) & (x < 2));
figure
stairs(x, y)
grid
axis([-1 3 -1 3])