14:440:127– Introduction to Computers for Engineers
Notes for Lecture 10
Rutgers University, Fall 2009
Instructor- Blase E. Ur
Rather than using the
statement, you can use Matlab to create a graphical menu, allowing the user to click on
their selection. The example below creates a menu and then uses
to identify which option was chosen.
Note that you must set the
command equal to a variable, just as you did with the
statement. The ﬁrst
input argument to the menu function is the text displayed on the top of the menu. All of the subsequent arguments
are the choices, which are strings separated by commas. The
function returns an integer indicating which
option was chosen.
food = menu(’Welcome to White Castle, may I take your order?’,
’Cheeseburger’,’Chicken Rings’,’Mr. Pibb and Red Vines’,’Ok’);
disp(’Good call on the cheeseburger.’)
disp(’Chicken comes in ring form?’)
disp(’Yo momma’’s so fat, she went to White Castle.
..looked at the menu.
.. and said OK’);
GUIs- Graphical User Interfaces
To make a GUI (graphical user interface) in Matlab, type
in the workspace. The GUI editor will pop up.
Choose ”Blank GUI”. You should see a grid, along with a bunch of buttons on the left. You can click and drag these
buttons onto the grid, and you’ll be making your interface. First, you design the aesthetics of your interface. Then,
click on the green ”play button” to the top right of the GUIDE editor and you’ll program all of the logic behind the
After programming the logic behind the interface, you’ll see that you’ve saved both a
of these ﬁles to make your GUI work! Also, if you want to edit the interface for your GUI after program-
ming part of it, type
in the workspace and choose the ”open existing GUI” tab.
Note that GUIs aren’t really covered in your book. Instead, you should check out the following web tutorial, from
which I took part of this lecture (and followed much of the same terminology): www.blinkdagger.com/matlab/matlab-
Properties of Objects
Each time you drag another button/text/thing into your interface when using
, you create a new ”object.”
An object can be a clickable button, an editable text box, a static (unchanging) text box, a graph, radio buttons, or
all sorts of fun, exciting, and glamorous things. Each ”object” has a number of properties that deﬁne its appearance.
You can change these properties by double clicking an object. A window like the following will open: