Why does it not work to close my figure programmatically in MATLAB 7.11 (R2010b)?
조회 수: 2 (최근 30일)
이전 댓글 표시
I am using this code in MATLAB 7.11 (R2010b) to create a infobox:
function g = infobox(text, header, notneeded)
if nargin < 2
header = 'Info box';
end
relWidth = 0.5;
relHeight = 0.1;
screenSize = get(0, 'ScreenSize');
height = min(1.1*1024,
screenSize(4));
width = min(1.1*1280, screenSize(3));
% Position of is relative to screen resolution
pos = [width*(1-relWidth)/2, height*(1- relHeight)/2, ...
width*relWidth, height*relHeight];
gColor = [0.92941 0.94118 0.9451];
g = figure('NumberTitle', 'off', ...
'MenuBar', 'none', ...
'Resize', 'off', ...
'Name', header, ...
'Color', gColor, ...
'Position', pos, ...
'WindowStyle', 'modal');
set(g,'HandleVisibility','off')
pp = getpixelposition(g);
uicontrol(g, 'Style', 'text', ...
'String', text,...
'HorizontalAlignment', 'left', ...
'BackgroundColor', get(g,'Color'),...
'FontName', 'Calibri', ...
'FontSize', 14,...
'Position', [0.1*pp(3) 0.05*pp(4) 0.8*pp(3) 0.9*pi(4)]);
pause(1)
end
This infobox should close after a while but this does not work:
infobox('test');
close(gcf)
댓글 수: 0
채택된 답변
Matt Fig
2011년 1월 20일
You set the 'HandleVisibility' property of the figure to 'off'. When you do this, gcf does not see the figure. Here is your code (formatted for others to be able to read it!) and how to call it
function g = infobox(text, header, notneeded)
if nargin < 2
header = 'Info box';
end
relWidth = 0.5;
relHeight = 0.1;
screenSize = get(0, 'ScreenSize');
height = min(1.1*1024, screenSize(4));
width = min(1.1*1280, screenSize(3));
% Position of is relative to screen resolution
pos = [width*(1-relWidth)/2, height*(1- relHeight)/2,width*relWidth, height*relHeight];
gColor = [0.92941 0.94118 0.9451];
g = figure('numbertitle', 'off', 'MenuBar', 'none', ...
'resize', 'off', 'name', header, ...
'Color',gColor, 'position',pos,...
'windowstyle', 'modal');
set(g,'HandleVisibility','off');
pp = getpixelposition(g);
R = uicontrol(g, 'Style', 'text', ...
'String',text,...
'HorizontalAlignment', 'left', ...
'BackgroundColor',get(g,'Color'),...
'FontName', 'Calibri', 'FontSize', 14,...
'Position', [0.1*pp(3) 0.05*pp(4) 0.8*pp(3) 0.9*pp(4)]) ;
pause(1)
end %%%END CODE%%%
Now when you call it from the command line and you want to close it, use:
g = infobox('test');close(g)
Also, there is an error in the 'position' property of your textbox. You should have written pp(4) as I show above, not pi(4).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!