You have the right idea, but both your x-coordinates and your y-coordinates for the line ends are wrong. For x, you should use:
x = 10:10:100;
This generates [10, 20, ..., 100]
. linspace(1, 100, 10)
on the other hand generates 10 equally spaced values between 1 and 100 - which is somewhat different. To get the same values using linspace
you would do linspace(10, 100, 10)
.
For y, because you use zeros
, the line only extends from zero to the upper y limit, rather than from the lower to the upper limit. Your call should instead be:
plot([x; x], repmat(ylim', 1, numel(x)), 'r')
This repeats the y-axis limits for each line, so the i
-th line is drawn from (x(i), ylim(1))
to (x(i), ylim(2))
.