How to get a figure into an axis in app designer?

49 Ansichten (letzte 30 Tage)
Kristin Habersang
Kristin Habersang am 1 Okt. 2021
Beantwortet: Dave B am 1 Okt. 2021
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!

Akzeptierte Antwort

Dave B
Dave B am 1 Okt. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by