Creating Graphical User Interfaces Previous page   Next Page


Axes enable your GUI to display graphics (e.g., graphs and images). Like all graphics objects, axes have properties that you can set to control many aspects of its behavior and appearance. See Axes Properties" in the MATLAB documentation for general information on axes objects.

Axes Callbacks

Axes can be programmed to execute a callback when users click a mouse button in the axes. Use the axes ButtonDownFcn property to define the callback.

Plotting to Axes in GUIs

If your GUI contains axes, you should make sure that the Command-line accessibility option in the GUI Options dialog is set to Callback (the default). If your GUI contains only one axes, this enables you to issue plotting commands from callbacks without explicitly specifying the target axes. See Command-Line Accessibility for more information about how this option works.

Displaying an Image on an Axes

This example shows how to display an image on an axes in a GUIDE-generated GUI. The example

To build the example:

  1. Open a blank template in the Layout Editor.
  2. Drag an axes into the layout area.
  3. Select M-file editor from the View menu.
  4. Add the following code to the opening function:

When you run the GUI, it appears as in the following figure.

MATLAB demos

The preceding code performs the following operations:

Displaying Plots in a Separate Figure

This code for this example is appropriate for a programatically generated GUI.

  1. Create a figure.
  2. Create an axes, save its handle, and set its Parent property to the figure handle.
  3. Create the plot, save its handles, and set the plot Parent property to the handle of the axes.

The following code illustrates these steps:

Note that not all plotting commands accept property name/property value specifications as arguments. Consult the reference page for the specific command to see what arguments you can specify.

GUIs with Multiple Axes

If a GUI has multiple axes, you should explicitly specify which axes you want to target when you issue plotting commands. You can do this using the axes command and the handles structure. For example,

makes the axes whose Tag property is axes1 the current axes, and therefore the target for plotting commands. You can switch the current axes whenever you want to target a different axes. See GUI with Multiple Axes for an example that uses two axes.

Previous page  Button Groups ActiveX Controls Next page

© 1994-2005 The MathWorks, Inc.