MATLAB: GUI – Figure Browser

browsercopyobjfigfugureguihandles

I have a folder with ca 50 plots (.fig) and I want to display them in a simple GUI with has a next and previouse button to display one figure at a time in certain area of the GUI.
I am able to replace the axes (handles.axes_disp) in GUI once with one of figure files but when I press one of the buttons for the second time, I cannot access the handle anymore.
[Merged information from comment]
GUI handles:
Button: handles.load_btn
Display axes: handles.axes2
'fig2.fig' is supposed to appear in the display area. But after the line copyobj I am losing the handle.
function load_btn_Callback(hObject, eventdata, handles)
ImportFig=hgload('fig2.fig',struct('visible','on')); % Open fig file and get handle
ImportFigAxes=get(ImportFig,'Children'); % Get handle to axes
% Get subplot axes info
NewFig=get(handles.axes2,'Parent'); % Get new (subplot) figure handle
SubplotPos=get(handles.axes2,'Position'); % Get position of subplot axes
delete(handles.axes2); % Delete blank subplot axes
% Copy axes over to subplot
NewSubplotAxes=copyobj(ImportFigAxes,NewFig); % Copy import fig axes to subplot
set(NewSubplotAxes,'Position',SubplotPos) % Set position to orginal subplot axes
% Delete figure
delete(ImportFig); % Delete imported figure

Best Answer

You delete handles.axes2 but you do not set it to any new value ?
(Also remember to use guidata(hObject, handles) after you update it with a new value.)
Related Question