MATLAB Creating Graphical User Interfaces

(ff) #1

  • Double-click the title, and change it to Select Contours of Peaks
    Function.

  • Double-click the X and Y axis labels, and press the Delete key to remove them.


(^2) Drag an Edit Field (Numeric) component below the axes on the canvas. Then make
these changes:



  • Double-click the label next to the edit field and change it to Levels:.

  • Double-click the edit field and change the default value to 20.


(^3) Drag a Button component next to the edit field on the canvas. Then double-click its
label and change it to Update Plot.
(^4) Add a callback function that executes when the user clicks the button. Right-click the
Update Plot button and select Callbacks > Add ButtonPushedFcn callback.
(^5) App Designer switches to the Code View. Paste this code into the body of the
UpdatePlotButtonPushed callback:
Z = peaks(100);
nlevels = app.LevelsEditField.Value;
contour(app.UIAxes,Z,nlevels);
(^6) Next, share the callback with the edit field. In the Component Browser, right-click
the app.LevelsEditField component and select Callbacks > Select existing
callback.... When the Select Callback Function dialog box displays, select
UpdatePlotButtonPushed from the Name drop-down menu.
Sharing this callback allows the user to update the plot after changing the value in
the edit field and pressing Enter. Alternatively, they can change the value and press
the Update Plot button.
Use One Callback for Multiple App Designer Components

Free download pdf