MATLAB: How to draw line vertical to Y-axis

ploty axis

Hey Matlab users,
If a = [1 2 3 4 5 6 7]; and b = [1 4 7 10 7 4 1]; and the plot it by : figure,plot(a,b), how can I draw let's say a red line vertical to the value 4 and 7 in the y-axis (parallel to x-axis)? So that i can see the window between 4 and 7.
Thanks so much in advance,
Mehdi

Best Answer

The same as for your previous question. The solution for that was
yL = get(gca,'YLim');
line([3 3],yL,'Color','r');
line([5 5],yL,'Color','r');
and if you are wanting to draw vertical lines at 4 and 7, you would just change the code to
yL = get(gca,'YLim');
line([4 4],yL,'Color','r');
line([7 7],yL,'Color','r');
Perhaps what you want is instead horizontal lines? If so then
xL = get(gca,'XLim');
line(xL,[4 4],'Color','r');
line(xL,[7 7],'Color','r');