필터 지우기
필터 지우기

MATLAB generating a ghost figure

조회 수: 7 (최근 30일)
Eric Snyder
Eric Snyder 2022년 1월 7일
댓글: Eric Snyder 2022년 1월 10일
I have a UI for brushing and labeling data. I've included a simplified version of the script below. The problem is that MATLAB is randomly generating a blank figure in addition to the GUI every time I run it. If I remove the "hold on; plot(DETECTIONS{i}, 'rx'); hold off" line and the "brush on" line, this extra figure is not generated. However, including either the hold on or the brush on portions causes MATLAB to generate a blank figure despite it never being explicitly asked to in the code. Any thoughts about why this could be happening and how to avoid it?
% initialize GUI
nplot = 4; % number of subplots
fig = uifigure('name', 'Label Detections');
grd = uigridlayout(fig, [nplot, 1]);
for i = 1:nplot
uipan(i) = uipanel(grd);
ax(i) = uiaxes(uipan(i));
end
% Find GUI figure, plot data on it
fig = findall(0, 'Type', 'figure', 'name', 'Label Detections')
for i = 1:nplot
plot(ax(i), DATA{i})
hold on
plot(ax(i), DETECTIONS{i}, 'rx')
hold off
end
brush on

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 1월 7일
You also need to specify the target axes/figure for your calls to hold and brush
You should probably be using a uifigure instead of figure. At least I get a warning that some of the functionality is not supported in figures.
Try this (untested)
hold(ax(i),'on') % and 'off'
brush(fig,'on')
  댓글 수: 5
Walter Roberson
Walter Roberson 2022년 1월 10일
I had no problem activing brush on a uiaxes
brush(ax(i), 'on')
Eric Snyder
Eric Snyder 2022년 1월 10일
I replaced uiaxes with axesand it now works just fine. I'm not sure what the problem was prior. It's possible a setting I had somewhere else in my code didn't get along with uiaxes, but as of now I haven't figured out why it gave me trouble.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 1월 7일
fig = figure('name', 'Label Detections');
That creates a "traditional figure"
grd = uigridlayout(fig, [nplot, 1]);
uigridlayout() cannot be children of traditional figures.
ax(i) = uiaxes(uipan(i));
uiaxes() cannot be children of traditional figures.
hold on
When you do not pass a parent to hold then it looks for the current axes, and creates a current axes if need be, which might involve creating a current figure. Only traditional axes (and traditional figures) are examined: the default never looks for uiaxes or uifigure.
You would need
hold(ax(i), 'on')
  댓글 수: 2
Eric Snyder
Eric Snyder 2022년 1월 7일
Oops, that's a typo. It should be uifigure, not figure. I edited the question. Thanks
Walter Roberson
Walter Roberson 2022년 1월 7일
Anyhow, hold on and brush on are your problems.

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

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by