MATLAB: GUI axes live plotting during pause and dialog box results in odd behavior

axesguihandlesplot

Hi all,
I've been scratching my head over this issue last few days and I can't seem to get a grasp of what's going on behind the scenes to make this occur.
Scenario: I am plotting three data vectors (y) against time (x) using "plot(handles.axes1,…." command which is preceeded by "set(1,'CurrentAxes,handles.axes1)". With this I'm able to successfully plot all three graphs, set xlim/ylim and other properties. If a callback executes "pause" the live plot still functions and there are no issues. However, if I try to then create an error dialog box, the plot switches to plotting inside the error dialog. If I generate the dialog box without a current pause being in effect, it plots as intended inside the GUI axes. There seems to be something that the function "pause" does to affect the plotting/drawing.
Is there a workaround I could do? I've tried getting rid of the "set(1,'CurrentAxes,handles.axes1)" before executing "plot(handles.axes1,…" but this results in only the first line being plotted and all subsequent properties to be ignored. It won't allow me to set xlim/ylim at all and the "hold on or all" function does not work. Even then, the error dialog becomes the "main axes" and everything is plotted there.
Any input is greatly appreciated! Thanks!

Best Answer

Why is anything plotted during the error dialog box is visible? You've explained, that the plots are created accurately at first and the error dialog appears, but where do the further lines come from?
set(1, 'CurrentAxes', handles.axes1) is not required, if you provide the 'Parent' property whenever an axes object is modified. E.g. "plot(handles.axes1,... is a good strategy already, although I'd prefer:
plot(x, y, 'Parent', handles.axes1)
Instead of xlim([a,b]) you can call xlim(handles.axes1, [a,b]) or:
set(handles.axes1, 'XLim', [a,b])
If this is applied reliably in all commands for drawing, the error dialog box will not be polluted by orphaned lines.
The pause command does allow all drawing events to be executed, similar to drawnow. This does e.g. start the creation of new axes and figures, such that further drawings e.g. from a timer's callback can be appear in a new axes. Therefore plot calls without specifying the parent object are not "thread-safe", as well as using cd together with relative file names etc.