I want to plot into matlab the following function y(x):
when x is between 1 and 2: y=1
when x is between 2 and 3: y=2
when x is between 9 and 10: y=9
I have tried a code. but this code only plots the curve for the final case (so y=9 when x is between 9 and 10).
I know that i can join 2 points like this:
plot([1 2],[1 1],[2 3],[2 2])
However, it will be tedious if i was to do this 10 times (or even more).
The Attempt at a Solution
I have tried the following code:
for i =1:10
x(i) = i
if j==i || j==i+1
plot([x(j) x(j+1)],[y(j) y(j)])
Any help or ideas will be very much appreciated.