How to get a figure into an axis in app designer?
34 views (last 30 days)
Show older comments
Hello,
how can I get my figure into an axis in app designer?
I already tried things like set(0, 'CurrentAxes', app.UIAxes) or allfigs = findall(0,'Type', 'figure'), but nothing works.
Thank you!
0 Comments
Accepted Answer
Dave B
on 1 Oct 2021
Normally in MATLAB the hierarchy is Figure - Axes - Chart (plot, bar, scatter, etc.), admittedly the terminology is a little confusing.
Do you mean you want to plot into your app designer axes? In this case, when you call the plotting function, just specify the UIAxes as the parent. Most charting functions will accept a parent/target as the first input. The syntax will look something like:
plot(app.UIAxes, x, y)
Note that it's often useful for apps to store the object inside the axes. That way if the data are adjusted, you can respond by updating the chart object (the Line in this case), instead of making a new one.
To do this you might make a new private property called MyLine, then maybe in the App's StartupFcn you might have code to create the line like:
app.MyLine = plot(app.UIAxes,nan,nan);
Then in a callback you might have something that sets MyLine's XData and YData:
% Button pushed function: Button
function ButtonPushed(app, event)
app.MyLine.XData = 1:10;
app.MyLine.YData = rand(1,10);
end
Apps don't use a 'current figure' or 'current axes', where gcf/gca return the current figure/axes and the default target for a plotting command is the 'current axes/figure'. This is intentional - a user of an app typically doesn't want to have their plotting commands routed to an axes in the app, and it would be really easy to break an app if a plotting command was routed directly to an App's objects.
0 Comments
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!