MATLAB GUI callback to open a new figure?
4 views (last 30 days)
Show older comments
Hello. I am trying to run a GUI program which opens when I run the source script file. When the script is run, a window opens with a pushbutton inside of it. When the user clicks on the pushbutton I want this window to close and a new one to open (or even better, the new window should replace the old one at the exact location on the screen). The next screen will also be a figure with its own set of pushbuttons and callbacks etc. I have figured out how to close the figure when the pushbutton is clicked by entering the required commands in the callback. However I can't seem to open a new figure. It leads to a destroyedcallback error and also says that the figure I tried to open didn't exist (although it does exist in the same location as the source script file). The pushbutton for the main window looks like this:
% --- Executes on button press in prob1push.
function prob1push_Callback(hObject, eventdata, handles)
% hObject handle to prob1push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h_help = findobj('Tag','prob1push');
if (isempty(h_help))
% Do something here -- window doesn't currently exist
else
closereq;
end
0 Comments
Answers (1)
Geoff Hayes
on 3 Nov 2017
Rahul - just call the name of the second GUI. i.e. if the name of the other GUI is OtherGUI, then just call it as
hGui = OtherGui('Visible','off');
to open it but keep it invisible. You can then use hGUI to change the position of the GUI and then make it re-appear.
set(hGui,'Position',[x y w h]);
set(hGui,'Visible', 'on');
where `[x y u v]` is the new position (and dimensions) of the GUI.
See Also
Categories
Find more on Interactive Control and Callbacks 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!