Creating Graphical User Interfaces |
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 Graphics documentation for general information on axes objects.
Axes Callbacks
Axes are not uicontrol objects, but 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). 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.
Note If your GUI is opened as the result of another GUI's callback, you might need to explicitly specify the target axes. See GUIs with Multiple Axes. |
Example: Displaying an Image on an Axes
This example shows how to display an image on an axes. The example
set(hObject, 'Units', 'pixels'); handles.banner = imread([matlabroot filesep 'demos' filesep 'banner.jpg']); % Read the image file banner.jpg info = imfinfo([matlabroot filesep 'demos' filesep 'banner.jpg']); % Determine the size of the image file position = get(hObject, 'Position'); set(hObject, 'Position', [position(1:2) info.Width + 100 info.Height + 100]); axes(handles.axes1); image(handles.banner) set(handles.axes1, ... 'Visible', 'off', ... 'Units', 'pixels', ... 'Position', [50 50 info.Width info.Height]);
When you run the GUI, it appears as in the following figure.
The preceding code performs the following operations:
banner.jpg
using the command imread
.
imfinfo
.
info.Width
and info.Height
, respectively. The width and height of the GUI are the third and fourth entries of the vector position
.
image(handles.banner)
.
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.
Button Groups | ActiveX Controls |
© 1994-2005 The MathWorks, Inc.