Creating GUI in Matlab involves creating two files, 1. For Laying out the GUI components (.fig file) 2. For Programming the GUI components (.m file or GUI M-file or application M-file)
THEORY Matlab provides an environment to make this task easier, called GUIDE.
GUIDE automatically generates the two files that are necessary for GUI development, 1. .fig file = uicontrols (and their childrens) with all properties (data + object) 2. .m file = functions that run and control the GUI and the callbacks
In the programming side (GUI M-file) there are basically two kinds of function in Matlab GUI. 1. The functions automatically written by Matlab for the GUI environment. 2. The functions written by you for your tasks.
The functions automatically generated by GUIDE are named after the name of your GUI. Thus, my_gui_OpeningFcn, where my_gui is the name of the GUI, is the opening function of any GUI which gets executed before the start of any GUI. Similarly my_gui_OutputFcn, outputs variables to the command line.
TERMS YOU SHOULD KNOW callbacks = functions that you want to execute when users activate components in the GUI (e.g., click on a push button); can be any function but mostly functions written by you for your tasks. handles = A structure containing the handles of all components in the GUI whose fieldnames are defined by the object’s Tag property. Can also be used to pass data to other callback functions or the command line. hObject = handle to the object that executes the callback, the objcet that calls a function Tag = property to name the callback subfunction in the GUI M-file
GET SET VALUES IN OBJECTS If you want to get value of something inside a function called by a object use this val = get(hObject,’Value’);
But, if you want to get the value of an object(TAG1) in the GUI from a function called by a second object try this val = get(handles.TAG1, ’Value’);
Similarly for setting the value of something inside the function called by an object use set(hObject,’BackgroundColor’,’white’);
And if you want to set the value of an objcet(TAG1) from another objcet use this set(hObject,’BackgroundColor’,’white’);
COMMON OPERATIONS
%switch case switch response case {’No’} % take action case ’Yes’ % take action end
%if..else if button_state == get(hObject,’Max’) % toggle button is pressed elseif button_state == get(hObject,’Min’) % toggle button is not pressed end
% Update handles structure by guidata(handles.TAG1, handles);