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

42 ビュー (過去 30 日間)
Kristin Habersang
Kristin Habersang 2021 年 10 月 1 日
回答済み: Dave B 2021 年 10 月 1 日
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!

採用された回答

Dave B
Dave B 2021 年 10 月 1 日
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 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by