This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 14:440:127– Introduction to Computers for Engineers Notes for Lecture 09 Rutgers University, Spring 2010 Instructor- Blase E. Ur 1 Menus Rather than using the input 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 switch case to identify which option was chosen. Note that you must set the menu command equal to a variable, just as you did with the input statement. The first 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 menu 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’); switch food case 1 disp(’Good call on the cheeseburger.’) case 2 disp(’Chicken comes in ring form?’) case 3 disp(’Crazy delicious!’) case 4 disp(’Yo momma’’s so fat, she went to White Castle...’) disp(’...looked at the menu... and said OK’); end 2 GUIs- Graphical User Interfaces To make a GUI (graphical user interface) in Matlab, type guide 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 interface. After programming the logic behind the interface, you’ll see that you’ve saved both a .fig and a .m file. You need both of these files to make your GUI work! Also, if you want to edit the interface for your GUI after program- ming part of it, type guide in the workspace and choose the ”open existing GUI” tab. It is extremely important to note that we’ve made a paradigm shift in our approach to computer programming when working with GUIs. Previously, our programs more or less ran from top to bottom, in order. With GUIs, we are basically doing things in an event-driven fashion. We have a function for each ‘event,’ such as a button being pressed or a user entering text. When that event happens, we run the code in the associated function. Therefore, you never really know in what order the functions will execute. Note that GUIs aren’t 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-gui- graphical-user-interface-tutorial-for-beginners 1 2.1 Properties of Objects Each time you drag another button/text/thing into your interface when using GUIDE , 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...
View Full Document
This note was uploaded on 03/20/2011 for the course ENGINEERIN 127 taught by Professor Finch during the Spring '08 term at Rutgers.
- Spring '08