Part 1
The problem is line 67:
handles.guifig = gcf;
handles.timer = timer('Period', 1.0, 'ExecutionMode', 'FixedRate','TimerFcn', {@increment,handles.guifig});
guidata(handles.guifig,handles);
When you call gcf a new figure is poofed to become the current figure. The reason for this is the GUIDE GUI's Figure's 'HandleVisibility' is set to 'off'. This is the GUIDE default and can be changed in GUIDE->tools->GUI Options.
So now you have a new figure created and you set the GUIDATA to this figure. Axes will be poofed on this figure and the rest explains the behavior you are seeing.
The simplest way to fix this is to set handles.guifig to be handles.figure1'. 'figure1' is the default tag for the gui figure. Of course this is redundant since now you'll have handles.guifig and handles.figure1 both pointing to the same thing. Thus the easiest (and probably best) fix is to rename the figure's tag to guifig in the GUIDE Property inspector. Or you could just go through your code and replace guifig with figure1, both work.
Part 2
As far as what IA was mentioning above with using:
imshow(the_image,'Parent',handles.axes1)
This is definitely a requirement so that imshow does not poof a new axes.
Alternatively, and this is what IA was hinting at, you can just set the 'CData' of the image to be different. For a robust real time application, I would argue that this the right way to do it. The reason for this is that it is faster and cleaner to change the coloring of an image than to delete that image and make a new image. As long as all of the other properties remain the same, we can skip the delete&repeat steps.
To do this, store the image handles in and update the 'CData' as necessary.
Here is a small example that outlines the idea.
hImage = imshow(cat(3,ones(200,400),zeros(200,400,2)));
T = timer('Period',1,'TasksToExecute',10,...
'Timerfcn',@(~,~)set(hImage,'CData',circshift(get(hImage,'CData'),[0 0 1])),...
'StartDelay',1,'ExecutionMode','FixedRate');
start(T);
Best Answer