Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
GUIDE
Praktikum Pemrosesan Bahasa Alami
GUIDE?
• MATLAB implements GUIs as figure windows containing various uicontrol objects.
• You must program each object to perform the action you intend it to do when a user activates the component.
• In addition, you must be able to save and run your GUI.
• All of these tasks are simplified by GUIDE, the MATLAB graphical user interface development environment.
GUI Development Environment
• Creating a GUI involves two basic tasks:
– Laying out the GUI components
– Programming the GUI components
Layout Editor
• GUIDE also generates an M-file that contains code to handle the initialization and launching of the GUI.
• This M-file provides a framework for the implementation of the callbacks -- the functions that execute when users activate components in the GUI
GUIDE Generated Files
• A FIG-file -- a file with a .fig file name extension, which contains a complete description of the GUI figure and all of its children (uicontrols and axes), as well as the values of all object properties. You make changes to the FIG-file by editing the GUI in the Layout Editor.
• An M-file -- a file with a .m file name extension, which contains the functions that run and control the GUI and the callbacks. This file is referred to as the GUI M-file. Note that the M-file does not contain the code that lays out the uicontrols; this information is saved in the FIG-file.
Example 1: Merekam Suara dan Mendengarkan
Rancangan GUI
M-File
Example 2
• We want to build GUI like this picture
Open GUIDE • Write guide at command window, then push
ENTER button at your keyboard
Choose Blank GUI
• At GUIDE quick start window, choose Blank GUI (Default).
• Then push OK.
Blank GUI
Using Static Text and Edit Text
• Put three Static Text and three edit text the Figure
Static text
Edit text
Push button
Change Static Text Property • Double click at first Static Text (text1)
• The Property Inspector will be opened
Change Static Text Property (2)
• Click the button at String property
• Then change the string to “ Enter First Number”
Change Static Text Property (3)
• Change the String property at second Static Text (text2) into “Enter Second Number”
Change Edit Text Property
• Double click at first Edit Text (edit1)
• Then change the String property to blank string
Change Edit Text Property (2)
• Change the String property ata second Edit Text (edit2) to blank string
Change Push Button Property
• Double click at the Push Button (pushbutton1)
• Then change the String property to “process”
Add another Static Text
• Add one Static Text under the Push Button
• Then change the String property into “Result”
Save the figure
• Choose File > Save at the menu bar
myfirstgui
• The file name is myfirstgui
The M-File • After myfirstgui.fig saved, the myfirstgui.m will be built and
opened
Write the code
• Find the btnProcess_Callback function, then write this codes under that function
a=get(handles.txtFirstNumber,'String');
a = str2num(a);
b=get(handles.txtSecondNumber,'String');
b = str2num(b);
c=a+b;
c=num2str(c);
set(handles.txtResult,'String',c);
• get is the function to get property value. In this example, is to get the String property value that entered by the user
• set is the function to set the property value
• str2num is the function to convert string data to number data
• num2str is the function to convert number data to string data
Run the gui
The result