Department of Electronic Engineering ES-304: Signals and Systems (Pr)
Mehran University of Engineering and Technology, Jamshoro
Experiment-14: GUI Development in MATLAB
Roll No.: _____________ Date of Conduct: _____________ Submission Date: _______________
Lab Performance Indicators
CLO-4 CLO-5
Understanding of Calculation, coding, Production and Lab interaction and Presentation of Score
tasks/activities (2) and implementation (2) interpretation of results (2) involvement (2) tasks/reports (2)
OUTCOME:
▪ The students will be able to MATLAB GUI for different applications of signals and systems
TOOLS:
▪ MATLAB R-2016a or higher version
BACKGROUND:
GUIDE, the MATLAB graphical user interface development environment, provides a set of tools
for creating graphical user interfaces (GUIs). These tools greatly simplify the process of designing
and building GUIs. You can use the GUIDE tools to:
• Lay out the GUI
Using the GUIDE Layout Editor, you can lay out a GUI easily by clicking and dragging GUI
components—such as panels, buttons, text fields, sliders, menus, and so on—into the layout area.
GUIDE stores the GUI layout in a FIG-file.
• Program the GUI.
GUIDE automatically generates an M-file that controls how the GUI operates. The M-file
initializes the GUI and contains a framework for the most commonly used callbacks for each
component—the commands that execute when a user clicks a GUI component. Using the M-file
editor, you can add code to the callbacks to perform the functions you want.
DEMO ACTIVITY:
1. Type guide on the command window, you
will see the following window:
Experiment-14: GUI Development in MATLAB 5-1
Department of Electronic Engineering ES-304: Signals and Systems (Pr)
Mehran University of Engineering and Technology, Jamshoro
2. Select Blank GUI‟ and click „ok‟. The following
screen will appear:
3. Design your GUI with the help of panel provided to the left, a sample GUI is shown in the
next figure:
4. Double click on an item opens „inspector‟, shown below, which
can be used to alter the properties of that particular entity.
5. Save your designed GUI.
6. Alter the code to cater for the changes that you want to make.
Experiment-14: GUI Development in MATLAB 5-2
Department of Electronic Engineering ES-304: Signals and Systems (Pr)
Mehran University of Engineering and Technology, Jamshoro
function varargout = GUI(varargin)
% GUI MATLAB code for [Link]
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUI
% Last Modified by GUIDE v2.5 29-Mar-2023 15:20:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_OpeningFcn, ...
'gui_OutputFcn', @GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GUI is made visible.
function GUI_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 GUI (see VARARGIN)
% Choose default command line output for GUI
Experiment-14: GUI Development in MATLAB 5-3
Department of Electronic Engineering ES-304: Signals and Systems (Pr)
Mehran University of Engineering and Technology, Jamshoro
[Link] = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = [Link];
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
msgbox('HELLOW WORLD :)')
%----------------------
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
sliderValue=get(hObject,'Value')
t=0:.01:1;
f=10;
plot(t,sin(2*pi*f*sliderValue*t))
%----------------------
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
Experiment-14: GUI Development in MATLAB 5-4
Department of Electronic Engineering ES-304: Signals and Systems (Pr)
Mehran University of Engineering and Technology, Jamshoro
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
checked=get(hObject,'Value')
%----------------------
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
radio=get(hObject,'Value')
%----------------------
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
text=get(hObject,'String')
%----------------------
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
contents = cellstr(get(hObject,'String'))
contents{get(hObject,'Value')}
%----------------------
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
Experiment-14: GUI Development in MATLAB 5-5
Department of Electronic Engineering ES-304: Signals and Systems (Pr)
Mehran University of Engineering and Technology, Jamshoro
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
contents = cellstr(get(hObject,'String'))
contents{get(hObject,'Value')}
%----------------------
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%----------------------
toggle_button=get(hObject,'Value')
%----------------------
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over popupmenu1.
Experiment-14: GUI Development in MATLAB 5-6
Department of Electronic Engineering ES-304: Signals and Systems (Pr)
Mehran University of Engineering and Technology, Jamshoro
ACTIVITIES:
1. Construct and write MATLAB code of a sample GUI containing two checkboxes. The
status of the checkboxes should be displayed in the corresponding textboxes according
to their selection, that either they are selected or not selected.
2. Design an oscilloscope using MATLAB GUIDE. Your design should contain the
features shown in figure.
Experiment-14: GUI Development in MATLAB 5-7