0% found this document useful (0 votes)
24 views7 pages

MATLAB GUI Development for Signals

The document outlines Experiment-14 for the Signals and Systems course at Mehran University, focusing on GUI development using MATLAB. It details the tools and methods for creating graphical user interfaces, including layout design and programming functionalities. Students are expected to construct a sample GUI and design an oscilloscope as part of their lab activities.

Uploaded by

Jogesh Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

MATLAB GUI Development for Signals

The document outlines Experiment-14 for the Signals and Systems course at Mehran University, focusing on GUI development using MATLAB. It details the tools and methods for creating graphical user interfaces, including layout design and programming functionalities. Students are expected to construct a sample GUI and design an oscilloscope as part of their lab activities.

Uploaded by

Jogesh Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

Common questions

Powered by AI

Effective handling of user inputs in MATLAB's GUIDE involves using callbacks tailored to changes in text or selection components like 'edit', 'popupmenu', and 'listbox'. For instance, using 'Callback' functions, the input values can be captured and immediately processed or validated. Strategies such as input sanitization and real-time validation ensure robustness and reliability. Moreover, these user inputs can be used to dynamically change other GUI elements or computational functions, thus enhancing interactivity and flexibility .

In MATLAB, setting the default background color is crucial for the visual consistency and customization of the user interface. For slider and popup menu components, the background color default settings ensure that these elements visually integrate with the operating system’s interface theme, particularly on Windows systems. This default consistency aids in creating a seamless user experience by reducing visual fatigue and distraction, aligning the GUI's appearance with industry expectations .

The 'inspect' tool in MATLAB GUI development is used to modify the properties of GUI components by providing an interface to access and change attributes such as position, size, and event callbacks. This tool speeds up development by allowing developers to directly manage and visualize changes in real-time, eliminating the guesswork involved in coding each property manually. By improving the accuracy and efficiency of component customization, it helps developers rapidly prototype and iterate on GUI designs .

The 'guidata' function is essential for updating the 'handles' structure that stores GUI component data, ensuring that the state of the GUI is current with user interactions. This function updates and retrieves the current state of handles, which is critical for complex GUIs as it maintains synchronization between the GUI's visual elements and their corresponding logic. This synchronization is vital when multiple callbacks occur simultaneously, as it prevents data inconsistencies and ensures smooth operation .

Defining initial values in the 'CreateFcn' of MATLAB GUI components is crucial as it sets the default state of these elements before user interaction occurs. This initial state can influence subsequent interactions by pre-setting components to expected values that align with the intended use-case or user guidelines, providing a ready-to-use interface. It also helps in managing user expectations and ensures that the GUI operates predictably from the moment it loads, facilitating an organized and user-friendly interaction experience .

The 'varargout' array in MATLAB is used to hold variable output arguments in functions, crucial for GUIs because it allows returning multiple outputs from the GUI script back to the MATLAB command line. It is typically employed in functions like 'GUI_OutputFcn', where it captures outputs to be returned to the command line, facilitating control and interactivity. By managing the information passed back from the GUI, it supports dynamic updates and interactions inherent in GUI operations .

The MATLAB GUIDE Layout Editor simplifies GUI development by providing a drag-and-drop interface to lay out GUI components such as buttons, panels, and text fields. This visual arrangement of components is saved in a FIG-file. The GUIDE Layout Editor interfaces with M-files that define the behavior of these components through callbacks, enabling a more intuitive design process without manually coding each interface element's positioning .

The 'slider1_Callback' function shows the practical application of a slider to adjust the 'Value' parameter dynamically. It captures the current slider value, which it then uses in the plotting equation for a sine wave. This interaction allows users to modify the frequency of the sine wave in real-time, thus providing a direct and visual way to manipulate data presentation. This enhances user interactivity by allowing real-time visual feedback in response to user input .

Callbacks in MATLAB GUIs are critical as they define the actions that occur in response to user interactions like button presses or slider movements. GUIDE assists in their implementation by automatically generating an M-file framework for common callbacks, allowing users to focus on customizing the response code within these callbacks. This separation of the user interface layout and the operational code enhances modularity and eases the debugging and enhancement of GUIs .

The singleton concept in MATLAB GUIs ensures that only one instance of the GUI can run at a time. This is implemented by configuring the GUI such that if an instance is already running, new requests to open the GUI bring the existing window to the foreground, rather than creating a new instance. This is beneficial because it prevents resource conflicts and redundancy, ensuring that all user interactions are managed in a single interface context, which can simplify state management and data handling .

You might also like