Creating Graphical User Interfaces    

Opening the GUI M-File

When you first save or run the GUI, GUIDE generates an M-file that contains all the callbacks. See GUI FIG-Files and M-Files. For each component that has a callback associated with it, GUIDE generates a framework for the callback, containing just a function definition. You must then add code to the callbacks to make them work. In this example, you add code to the callbacks for the three push buttons and the pop-up menu. For more information, see Understanding the GUI M-File.

You can edit the M-file code by clicking the M-file Editor icon on the toolbar. If you previously saved or ran the GUI, pressing the M-file Editor icon displays the M-file in the MATLAB editor. Otherwise, GUIDE does two things:

Type a name for the FIG-file in the File name field. GUIDE assigns the same name to the M-file. When you click Save, GUIDE saves the M-file and opens it in the M-file Editor.

You can view a list of the callbacks in the M-file by clicking the function icon on the toolbar, as shown in the following figure.

Clicking a callback in the pop-up menu moves the cursor in the editor to the first line of the callback. For example, click simple_gui_OpeningFcn to display the opening function, as shown in the following figure.

You can add code to the opening function to create data for the GUI, or perform other tasks, as described in the next section.


  Set Properties for the GUI Components Opening Function