We have learned to create a multipage form single GUI. This is not a
very clean approach, because all the panels are on same position and it
is sometime very hard to edit one panel later on. This example shows you
to create different GUI for different pages/slides and create a master
gui to control them.
(See the previous Note on Multipage GUIs, at http://www.facebook.com/notes/matlab-by-examples-book/gui-working-on-multislides-form/155932614460266)
Handles
Creating Slide Pages
First of All create two guis both (GUI1.m and GUI2.m) with two edit box edit1,edit2 and two pushbutton pushbutton1 with title Next and second pushbutton pushbutton2 with title Previous.
Now for navigation we will add too fields to each gui, next and prev.
So first in OpeningFcn add this two lines both in gui1 and gui2
Now go to pushbutton1_callback and add these line for displaying the next slide and disappearing itself
Now create a blank GUI with a pushbutton titled "Start" and save it as gui0.fig. This will automatically create a gui0.m file.
Now in this file, go to guiOpeningFcn
and you will find the followin code there
Now edit this code to call two slides and save their references to it.
Now we need to code the start button to hide the master page and start the silde1.
Here it is .. simple enough now..
Final Touch: Processing your data
Now once you are done , you return to master page again because next slide of the s2 is masterpage.
Here you need to collect all the data and do whatever you want. As an example I will add all the 4 number together which were written in 4 editboxes. For easeness, Put one more button titled "Submit" and one Editbox titled Result on masterpage and write the calculation code in Submit_callback. Needless to say that you need to press this submit button once you are back on masterpage to do the final editing.
Here is the calculation code for your reference
(See the previous Note on Multipage GUIs, at http://www.facebook.com/notes/matlab-by-examples-book/gui-working-on-multislides-form/155932614460266)
Handles
Remember:GET HANDLES
Each GUI has a structure called handles. To see or edit this structure , you can call guidata.
h=guidata(gui_reference);SET HANDLES
guidata(gui_reference,h);gui_reference is a double number which works as a pointer to the gui. To store this pointer as a variable, you need to call gui with an output
gui_reference=gui1;Note that gui's handles.output also contain this pointer. You can use this output when you are writing code inside that gui.
Creating Slide Pages
First of All create two guis both (GUI1.m and GUI2.m) with two edit box edit1,edit2 and two pushbutton pushbutton1 with title Next and second pushbutton pushbutton2 with title Previous.
Now for navigation we will add too fields to each gui, next and prev.
So first in OpeningFcn add this two lines both in gui1 and gui2
function gui1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to a1 (see VARARGIN)
% Choose default command line output for a1handles.output = hObject;
handles.next = 1 ;
handles.prev = 1 ;
% Update handles structureguidata(hObject, handles);
Now go to pushbutton1_callback and add these line for displaying the next slide and disappearing itself
set(handles.next,'Visible','On');for pushbutton2_callback do this to display previous slide.
set(handles.output,'Visible','Off');
set(handles.prev,'Visible','On');Creating Master Slide
set(handles.output,'Visible','Off');
Now create a blank GUI with a pushbutton titled "Start" and save it as gui0.fig. This will automatically create a gui0.m file.
Now in this file, go to guiOpeningFcn
and you will find the followin code there
function gui0_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to gui0 (see VARARGIN)% Choose default command line output for gui0handles.output = hObject;
% Update handles structureguidata(hObject, handles);
Now edit this code to call two slides and save their references to it.
As you can see, I have called gui1 and gui2 and saved there reference or pointers to handles.s1 and handles.s2. Now for navigation, we added the s2 to the next of s1(slide 1) and mastergui as previous of s1. Similarly for s2.% Choose default command line output for a1handles.output = hObject;
handles.s1= gui1;
handles.s2= gui2;
h1=guidata(handles.s1);
h1.next = handles.s2;
h1.prev = hObject;
guidata(handles.s1,h1);
h2=guidata(handles.s2);
h2.prev = handles.s1;
h2.next = hObject;
guidata(handles.s2,h2);
% Update handles structureguidata(hObject, handles);
handles.output
%set(handles.output,'Visible','off');set(handles.s1,'Visible','off');
set(handles.s2,'Visible','off');guidata(hObject, handles);
Now we need to code the start button to hide the master page and start the silde1.
Here it is .. simple enough now..
set(handles.output,'Visible','off');remember that handles.output indicate the pointer to gui itself.
set(handles.s1,'Visible','on');
set(handles.s2,'Visible','off');
Final Touch: Processing your data
Now once you are done , you return to master page again because next slide of the s2 is masterpage.
Here you need to collect all the data and do whatever you want. As an example I will add all the 4 number together which were written in 4 editboxes. For easeness, Put one more button titled "Submit" and one Editbox titled Result on masterpage and write the calculation code in Submit_callback. Needless to say that you need to press this submit button once you are back on masterpage to do the final editing.
Here is the calculation code for your reference
h1=guidata(handles.s1);Here you are done. The benefit of the master page is that you can rearrange your slides very easily and each gui is independent.
a1=get(h1.'edit1','String');
a2=get(h1.'edit2','String');
h2=guidata(handles.s2);
a3=get(h2.'edit1','String');
a4=get(h2.'edit2','String');
a=str2num(a1)+str2num(a2)+str2num(a3)+str2num(a4);
set(handles.result,'String',a);
I have built some gui program
ReplyDeletefirst is of login & second is of simple gui. now i want to link both in such a manner that first login & if login is successful then go to second gui using same program.
but i cann't do this.
if you can then please help me.
i'm waiting for your response.
links for programs are
(i) http://rajivcan.blogspot.in/2012/04/login-program-using-matlab-gui.html
(ii) http://rajivcan.blogspot.in/2012/04/simple-gui-program-using-matlab.html
@rajiv
ReplyDeletethis is pretty easy. Write a check code in the login pushbutton which varifies the
login details. if the password matches, call the other gui by writing just the gui name
suppose ur second gui is named gui2
write this in ButtonLogin_callback()
function ButtonLogin_callback()
%write other stuff to verify
Login_success=1; % change this to actually verify the login
if (Login_success)
gui2;
set(handles.figure,'Visibility',false);
end
hi buddy.
ReplyDeleteplease help me.
% --- Executes on button press in login.
function login_Callback(hObject, eventdata, handles)
% hObject handle to login (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ID = get(handles.edit1,'string');
PW = get(handles.edit2,'string');
if strcmp(ID,'admin') && strcmp(PW,'admin')==1
msgbox('login sukses');
aplikasi.fig;
set(handles.figure,'Visibility',false);
else
errordlg('Invalid username or password');
end
gui2 (aplikasi.fig) does not show up when a successful login.
I want to enter username in giu and that wiil be save after in database with want change in next slie..How to do that?
ReplyDeletethanks alot code is really helpful:):)
ReplyDeleteyeah..its really helpful..but the problem I got, for multiple GUIs it shows all the windows order wise (visible),,then it works as visibility defined. But primarily it opens all the windows. It will be very helpful if u kindly help me..
ReplyDeleteHello,
ReplyDeletethanks, this code is indeed very helpful.
My problem is, that each time I run the Start-GUI, it opens/runs all the other pages, too.
But the other pages need input from the previous pages, so it doesn't work.
How can I change that?
I'd be very grateful for every idea!!
Hello guys hope anyone can help me I'm beginner !!where can I put this code in my GUI
ReplyDeleteh=guidata(gui_reference);
guidata(gui_reference,h);
gui_reference=gui1;
This comment has been removed by the author.
ReplyDeletecowboys football
ReplyDeletepackers football
seahawks football
steelers football
vikings football
Hotel front desk software
ReplyDeleteFront Desk is a comprehensive practice management solution offering complete patient satisfaction, with the tools you need to connect with staff and provide the exceptional customer service your patients deserve. ... Read more about the Front Desk Practice Management System®.
Wow, so beautiful and wonderful post! Thanks for giving an opportunity to read a fantastic and imaginary blog. It gives me lots of pleasure and interest. Thanks for sharing. If you need any technical support related QuickBooks, click here, QuickBooks Customer Service Number for immediate solution.
ReplyDeleteHey! Fabulous post. It is the best thing that I have read on the internet today. Moreover, if you need instant support for QuickBooks Error, visit at QuickBooks Customer Service Our team is always ready to help and support their clients.
ReplyDeleteThanks for sharing such useful information with us. I hope you will share some more info about your blog. Please keep sharing. We will also provide QuickBooks Support Phone Number for instant help.
ReplyDeleteHey! Excellent work. Being a QuickBooks user, if you are struggling with any issue, then dial QuickBooks Customer Support Number Our team at QuickBooks will provide you with the best technical solutions for QuickBooks problems.
ReplyDeleteHey! Nice Blog, I have been using QuickBooks for a long time. One day, I encountered QuickBooks Enterprise Support in my software, then I called QuickBooks Support Phone Number (855)538-8273. They resolved my error in the least possible time.
ReplyDelete