Why does it not work to close my figure programmatically in MATLAB 7.11 (R2010b)?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Matt Fig
el 20 de En. de 2011
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).
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Object Properties en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!