I have two guis and when i call gui2 from gui1 using a continue button, gui2 does not work. However, gui2 works on its own when opened using guide. I have included the code below, please help!

function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% get the handle of Gui1
h = findobj('Tag','Gui1');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to Gui1
g1data = guidata(h);
% maybe you want to set the text in Gui2 with that from Gui1
set(handles.text1,'String',get(g1data.edit1,'String'));
end
open page1.fig
close(Opening_Page)

4 Comments

If you just call the name of the second gui its enough.No need to mention the '.fig'.Remove open also.Just page1 is sufficient to call the gui. If you still find the problem have a look at this Link
B.k. - please post our comment as a solution.
Note that GUI fig files are not meant to be run from the command line or to be double-clicked form within a file browser. They contain layout information and show what the GUI looks like. Any sort of initializations that is expected for the GUI would not occur when trying to "run" the figure file. It is the m file that we use to launch the GUI.
B.k, We tried the method you suggested, but it only opens the .m file and not the gui. What would you suggest we do for that?
@Geoff, If we can only use a .m file to launch a GUI, then what can we do in order to move from one gui to another using only the pushbutton?

Sign in to comment.

 Accepted Answer

Preethi - as B.k. indicated, don't use open. Instead do the following
function pushbutton5_Callback(hObject, eventdata, handles)
% launch the new GUI
page1;
% close the existing GUI
close(handles.figure1);
In the above, I am assuming that page1 is the name of the other GUI that you want to open. I'm also assuming that figure1 is the tag for your current GUI (the one that you want to close). See http://www.mathworks.com/matlabcentral/answers/271560-have-a-pop-up-dialog-which-has-license-agreement which does something similar.

8 Comments

Thank you. Gui2 now works after using the pushbutton. But, gui1 still does not close when gui2 opens. What change can i make to the code you've given us?
Is figure1 the name of the GUI? Do you observe an error when the line
close(handles.figure1);
is called?
The name of the second gui is page1. And these are the errors i am getting when clicking on the continue button.
Reference to non-existent field 'Opening_Page'.
Error in Opening_Page>pushbutton5_Callback (line 94)
close(handles.Opening_Page);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Opening_Page (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Opening_Page('pushbutton5_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
closereq
should do to close the current GUI. Your error does suggest there may be something more fundamental wrong though unless you have just mixed up your GUI tags.
Adam, Thank you so much. It works without any errors now!
Preethi - the error message is telling you that you are trying to access a field that doesn't exist within handles. You are using Opening_Page which is (probably) the name of the GUI and not the value assigned to the Tag property of your GUI/figure.
Geoff, I have changed the tags now, but am now getting this error.
Attempt to reference field of non-structure array.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB 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!