GUI Tutorial
Making Graphical User Interfaces in Matlab is very simple. A good place to begin learning about GUI development on the Matlab platform is to first understand how Matlab manages graphical objects.
How Does Matlab GUI Work
Inspector Property
GUI in Matlab is in essence a collection of objects. Every object in the GUI has a unique handle (name), This handle will allow developers to access the objects properties
i.e: let’s say we wanted to change the text on the button from 'Push Button' to 'Press ME'. All we have to do is obtain the object’s handle. Once we have the handle we can then set the 'text' property of the object to 'Press ME'.
to change it for any object , you had to open the property inspector (Right click ) then you will find as in figure.Property Inspector,
you will need to Change String and Tag to your needed data.
String : is the name of the object that viewed in the GUI.
Tag: is the name of the object that will be used in control the component (object)
NB: every component has difference Property Inspector (PI) but all of them contain sting/tag property .
How do I obtain the Handle of an Object ?
Inspector Property |
GUI in Matlab is in essence a collection of objects. Every object in the GUI has a unique handle (name), This handle will allow developers to access the objects properties
i.e: let’s say we wanted to change the text on the button from 'Push Button' to 'Press ME'. All we have to do is obtain the object’s handle. Once we have the handle we can then set the 'text' property of the object to 'Press ME'.
to change it for any object , you had to open the property inspector (Right click ) then you will find as in figure.Property Inspector,
you will need to Change String and Tag to your needed data.
String : is the name of the object that viewed in the GUI.
Tag: is the name of the object that will be used in control the component (object)
NB: every component has difference Property Inspector (PI) but all of them contain sting/tag property .
How do I obtain the Handle of an Object ?
Example………
>> fig = openfig('test.fig'); %loads the figure.
>> handles = guihandles(fig) %Gets handles.
To obtain a handle in the previous version the user must poll the object for it’s handle. To
poll the object the user must give every GUI object a unique ‘Tag’. For instance the
default tag for the ‘PushButton’ is ‘pustbutton1’. There for the following is what the user
would need to do in order to obtain the handle of the object.
how to open the GUI:
>> guide
in command window or click on in the guide button from the tool bar.
how to get the object:
>> pushbutton1_handle = findobj(‘Tag’,’pushbutton1’);
now you got the pushbutton1 handler and can work on it.
how do we change properties?
Matlab has two very important functions, which allow the user to alter an object’s properties at their discretion. These functions are listed below.
GET: Get object properties.
GET(H,'PropertyName') returns the value of the specified property for the graphics object with handle H.
SET: Set object properties.
SET(H,'PropertyName',PropertyValue) sets the value of the specified property for the graphics object with handle H.
SUMMARY:
• Guihandle() -> This function obtains all the handles in the GUI.
• Get() -> Allows users to obtain an object for a single property at runtime.
• Set() -> Allows users to change an objects property at runtime.
References:
- http://www.mathworks.com/discovery/matlab-gui.html
- http://blogs.mathworks.com/videos/category/gui-or-guide/
- http://www.mathworks.com/matlabcentral/answers/30070-gui-guide-tutorials
- http://www.fatih.edu.tr/~aserdogan/Matlab/MatLabGUItutorial.pdf