MATLAB: Plot pause

MATLAB

Hello
I am using the following code to iteratively pan along the x-axis in small steps and it works fine.
asig = csvread('tek0001CH1.csv',15,0);
%tim =sig(1:1000000,1);
aamp = asig(1:2000000,2);
ts = asig(2,1) - asig(1,1);
tim = [0:2000000 - 1]*ts;
time = tim';
plot(time, aamp);
%set(h,'Motion','horizontal','Enable','on');
axis([0 max(tim) -0.1 1.9]);
ax_handle = gca;
xlimit_orig = get(ax_handle, 'Xlim');
win_xlimit = [0 0.001];
offset = 0.001;
% %Iterativley change the xlimit for the axes to pan across the figure
while win_xlimit(2) <= xlimit_orig(2)
set(ax_handle, 'Xlim', win_xlimit);
pause(0.05);
win_xlimit = win_xlimit + offset;
end
However, if I want to stop in the middle of panning (If I see something of interest in the plot), how do I do it? I tried using waitforbuttonpress fcn and that doesn't work very well. Any suggestions please.
Thanks

Best Answer

You can use a toggle button:
buttonH = uicontrol('Sytle', 'ToggleButton', ...
'Units', 'pixels', ...
'Position', [5, 5, 60, 20], ...
'String', 'Pan', ...
'Value', 1);
while win_xlimit(2) <= xlimit_orig(2)
set(ax_handle, 'Xlim', win_xlimit);
pause(0.05);
if get(buttonH, 'Value') == 1
win_xlimit = win_xlimit + offset;
end
end