Displaying Graphics in App Designer
In this section...
“Calling Graphics Functions” on page 14-10
“Displaying Plots Using Other Types of Axes” on page 14-11
“Unsupported Functionality” on page 14-12
Displaying graphics in App Designer requires a different workflow than you typically use
at the MATLAB command line. Once you understand this workflow and a few special
cases, you will know how to call the functions you need for displaying almost any type of
plot.
Calling Graphics Functions
Many of the graphics functions in MATLAB (and MATLAB toolboxes) have an argument
for specifying the target axes or parent object. This argument is optional in most contexts,
but when you call these functions in App Designer, you must specify that argument.
Otherwise, MATLAB uses gcf or gca to get the target object for the operation. However,
gcf cannot return an App Designer figure, and gca cannot return any axes within an App
Designer figure. Thus, omitting the argument might produce unexpected results.
This code shows how to specify the target axes when plotting two lines. The first
argument passed to plot and hold is app.UIAxes, which is the default name for the
App Designer axes.
plot(app.UIAxes,[1 2 3 4],'-r');
hold(app.UIAxes);
plot(app.UIAxes,[10 9 4 7],'--b');
Some functions (such as imshow and triplot) use a name-value pair argument to
specify the target object. For example, this code shows how to call the imshow function in
App Designer.
imshow('peppers.png','Parent',app.UIAxes);
Whether you specify the target object as the first argument or a name-value pair
argument depends on the function. See the documentation for the specific function you
want to use to determine the appropriate arguments.
14 App Designer Basics