I have working code that draws vertical lines on a plot. Here's the line of code to first create the initial plot:
h = figure; plot(S2(:,1),S2(:,2)); xlim([handles.f_low,handles.f_high])
I'm using a GUI interface created in GUIDE, which is why there are references the handles structure. The x-axis limits are defined by me, but Matlab automatically determines the y-axis limits from the plot command. There a few other non-essential things like adding plot title and making the y-axis into log scale. The essential (and troublesome) line of code is this:
line([handles.f1_peak,handles.f1_peak],get(gca,'YLim'),'Color','k');
It worked fine initially. Then I tried adding lines of code preceding this which tweak the automatically generated y-axis limits by making them slightly larger.
y_axis_limits = get(gca,'YLim');
y_axis_limits(2) = y_axis_limits(2) + y_axis_limits(2)*.1;
set(gca,'YLim',y_axis_limits);
When I run the debugger it seems that everything is fine, it just makes the y-axis scale a little higher at the top without affecting bottom cutoff. But this results in the line command completely breaking without any error message or anything. It just doesn't do anything! That line of code executes, and nothing happens. As if it drew the line somewhere outside of the plot limits?? I don't get it..........