How do you set the focus to a specific uiaxes

조회 수: 14 (최근 30일)
James Kirk
James Kirk 2018년 11월 7일
댓글: Walter Roberson 2024년 9월 6일
I am designing an app with the new App Designer format and would like to be able to set the focus of my uifigure to draw on a specific set of uiaxes when I activate a particular callback.
When I attempt to target the axis for plotting using
axes(app.UIAxes)
I get the following error:
Error using axes
Functionality not supported with figures created with the uifigure function.
And calling:
uiaxes(app.UIAxes)
yields:
Error using uiaxes (line 32)
UIAxes cannot be a child of UIAxes.
Is it possible to set the current axes/panel of a uifigure object via their handle? How do I go back add a plot to uiaxes after having created them and subsequently edited other components on the uifigure?

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 11월 7일
I would recommend using the plot(ax,___) syntax.
" plot(ax,___) creates the line in the axes specified by ax instead of in the current axes (gca). The option ax can precede any of the input argument combinations in the previous syntaxes."
What I typically do is create a startup function that generates the initial plot
function startupFcn(app)
...
app.p1 = plot(app.UIAxes,x,y1)
...
end
Then, when I want to update my line, my app just updates the XData and YData properties of app.p1
% Update line
app.p1.XData = x_new;
app.p1.YData = y1_new;
Of course, this all depends on what type of plot you want to create.
BTW, startup function is a callback of the app canvas. See this page for how to add/create it.
  댓글 수: 7
Wes Baldwin
Wes Baldwin 2024년 9월 6일
+1
Walter Roberson
Walter Roberson 2024년 9월 6일
Note with respect to spectrogram() :
spectrogram() has no way of passing in a figure / uifigure or an axes / uiaxes
spectogram() does a gcf() . By default, HandleVisibility is off for uifigure(), so by default uifigure are skipped over. Probably a new figure() will be created to satisfy the gcf(). However, you can deliberately set HandleVisibility to on for uifigure, in which case gcf() will find the uifigure
spectogram() does a nextplot() with no parameters. If the nextplot is marked as replace or replacechildren then nextplot() will clf(), which will destroy the current axes. Otherwise nextplot is marked as new or add. If an axes is found then it is cla() . If no axes is found then nextplot uses axes('parent', fig) to create one.
So... by manipulating HandleVisibility you can get spectogram to plot inside a uifigure, and it will be able to find the current uiaxes. It will cla() the uiaxes, but that will leave the position intact.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 9월 6일
Somewhere around R2020b (possibly R2020a) it became possible to axes() the handle to a uiaxes to bring it into focus.
(It did not work in R2019b; I do not happen to have R2020a installed to test with.)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by