problem with overlapping of axis of loaded fig-files in GUI

1 view (last 30 days)
Hi there,
I have a set of fig-files and made a small GUI with two buttons (previous and next) to load the previous or the next fig-file. I realised that for example with the next-button as follows in the callback function:
------------------------------------------
handles.z1=handles.z1+1;
guidata(hObject, handles)
hFigure = openfig(['test' num2str(handles.z1) '.fig'], 'new', 'invisible');
hAxes = get(hFigure, 'CurrentAxes');
hCopy = copyobj(hAxes, handles.t);
set(hCopy, 'Position', [0.07 0.2 0.38 0.6])
-------------------------------------------
That function works but the problem is, that all following fig-files after clicking the buttons are overlapped in the GUI. I tried to add the following two lines in the end of the callback function:
-----------------------
waitforbuttonpress
delete(hCopy)
-----------------------
But that works only sometimes and is not a smart solution. Of course I could set the axes invisible, but I need to see the titles and axis of the loaded figures. Or I tried to delete the children of the GUI, where the fig-files are loaded in, but it also doesn't work. I am very new with GUI, does anyone have an idea to "clean" the previous loaded fig-file from the GUI so there won't be an overlap anymore?
Thanks

Answers (2)

Geoff Hayes
Geoff Hayes on 24 Nov 2014
Otto - you could try using clf which clears the current figure window, deleting all graphics objects of the figure. For example, you could try adding the following line as the first line in your next button callback
clf(handles.t,'reset');
The above may do what you want.
Also, since you are loading/opening a new figure (on each back or next button press), you should delete the the figure when you are finished with it. Try adding the line
close(hFigure);
to your push button callbacks.

Otto
Otto on 24 Nov 2014
Thanks for your help, but i found the solution as follows:
--------------------------
if handles.z1>0
h = findobj('Tag','1');
delete(h);
end
handles.z1=handles.z1+1;
guidata(hObject, handles);
hFigure = openfig([num2str(handles.z1) '.fig'], 'new', 'invisible');
hAxes = get(hFigure, 'CurrentAxes');
hCopy = copyobj(hAxes, handles.t);
set(hCopy, 'Position', [0.07 0.2 0.38 0.6]);
set(hCopy, 'Tag', '1');
close(hFigure)
--------------------------
I set the Tag of the axes hCopy on '1' (for the next button). So, after the next button press, i am searchig for this axes and delete it. close(hFigure) at the end closes the opened invisible fig-file (think its a cleaner way). May be there is a more elegant solution, but it works.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!