Sunteți pe pagina 1din 17

:

GUI Graphical User


Interface
Introduction to GUIDE
Creating a GUI
Overview of GUIDE layout techniques and tools
Programming the M-file that controls your GUI
Starting GUIDE

To start GUIDE, enter guide at the MATLAB prompt. This displays


the GUIDE Quick Start dialog, as shown in the following figure
Starting GUIDE, Cont.

From the Quick Start dialog, you can:


Create a new GUI from one of the GUIDE templates --
prebuilt GUIs that you can modify for your own
purposes.
Open an existing GUI.
Once you have selected one of these options, clicking
OK opens the GUI in the Layout Editor, which is the
control panel for all of the GUIDE tools.
The Layout Editor
The Layout Editor, Cont.

You can lay out your GUI by dragging components,


such as push buttons, pop-up menus, or axes, from
the component palette, at the left side of the Layout
Editor, into the layout area. For example, if you drag
a push button into the layout area, it appears as in
the following figure.
You can also use the Layout Editor to set basic
properties of the GUI components.
The Layout Editor, Cont.
The Property Inspector
Guide Templates,Cont.
Running a GUI

To run a GUI, select Run from the Tools menu, or


click the run button on the toolbar. This displays the
functioning GUI outside the Layout Editor.

For example, when you run the GUI with Axes and
Menu template, it appears as shown in the next slide.
This GUI displays various MATLAB plots. Select a
plot from the pop-up menu and click Update.
This example shows how to build user GUI in Matlab. We will build a simple calculator to
do that.
Start gui builder by typing
>>guide

Select "Blank GUI", click OK


The GUI window will open

Resize the design window.


Using the pallette on the left, drag and drop, resize and position the canvas, buttons, and
static text windows.
Double-click on an object to open the properties dialog. Change the captions on the
buttons and remove "Static Text" string from the text window. Set the font size 30 for the
text windows and change horizontal alingment to "right."
The GUI is finished. Save the work.
The rest of the design process will take care of the functionality provided by each GUI
component.
Open the matlab editor by typing
>>edit foo.m
where foo.m is the name of your design
Each time you press a button, a callback function is executed.
For example, in this particular case, a click on button "1" will call the following function:

This function will have to be modified to provide required functionality.


Buttons "0"-"9","+","-","*","/" will add corresponding symbol to the text string displayed
on the top. For button "1" the code will look like:
Do the same for the rest of the buttons, except "=".
The "=" button should evaluate the text string in the text window and return the result.

Now the calculator is ready to use. Of course, it misses a lot of functionality, but
1. Add next function:

Sin

Cos

Tg

Ln

Log

Log2

S-ar putea să vă placă și