Specifications

Programming Callbacks for GUI Components
4-15
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” on
page 4-16.
Example: Displaying an Image on an Axes
This example shows how to display an image on an axes. The example
Displays an image file on an axes.
Resizes the axes to fit the image.
Resizes the GUI so that its width and height are 100 pixels larger than the
image file.
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:
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.