Why does it not work to close my figure programmatically in MATLAB 7.11 (R2010b)?

2 ビュー (過去 30 日間)
Adity
Adity 2011 年 1 月 12 日
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)

採用された回答

Matt Fig
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 ExchangeGraphics Object Properties についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by