figure creation - cant access figure properties

figure creation - cant access figure properties

Post by Matthew O' » Fri, 31 Jul 2009 18:57:01


Hi I have a function which creates an info box with 3 dialogs. I want to close the box with the 'OK!' button. I have used 'callback','close(h0)' for the push button. If i run this on the command line (i.e. not as a function) h0 - h4 are created and everything works fine, however if i run it as a function I get the error:

??? Undefined function or variable 'h0'.

??? Error while evaluating uicontrol Callback

If i break the function before the end then i can see the variables so how come they disapear after the figure is created?? Please can someone explain then how to close the figure using the push button.

Many thanks

Matt

CODE:

function dia_out(dialog1, dialog2, dialog3)

dialog1 = 'bob' % for testing
dialog2= 'bob'
dialog3= 'bob'

h0 = figure('Color',[0.8 0.8 0.8], 'Colormap','default', ...
'PaperPosition',[18 180 256 432], ...
'PaperUnits','points', 'Position',[300 500 600 120], ...
'Tag','out_dialog', 'Name','Output Information',...
'NumberTitle','off','MenuBar','none');

h1 = uicontrol('Parent',h0, 'Units','points', 'ListboxTop',0,'Position',[20 55 300 25], ...
'HorizontalAlignment','left','String',dialog1, 'Style','text','FontSize',14);

h2 = uicontrol('Parent',h0, 'Units','points', 'ListboxTop',0,'Position',[20 30 300 25], ...
'HorizontalAlignment','left','String',dialog2, 'Style','text','FontSize',14);

h3 = uicontrol('Parent',h0, 'Units','points', 'ListboxTop',0,'Position',[20 5 300 25], ...
'HorizontalAlignment','left','String',dialog3, 'Style','text','FontSize',14);

h4 = uicontrol('Parent',h0, 'Units','points', ...
'BackgroundColor',[0.9 0.9 0.8], 'ListboxTop',0, ...
'Position',[350 60 70 20], 'String','OK!', ...
'Tag','Pushbutton1','callback', 'close (h0)' ,'Style','pushbutton','FontSize',14);
 
 
 

figure creation - cant access figure properties

Post by Bruno Luon » Fri, 31 Jul 2009 19:14:02


The string callback is evaluated in the *base* workspace (that is why h0 is unknown). Set the callback to anonymous/nested or other function forms.

Bruno

 
 
 

figure creation - cant access figure properties

Post by us » Fri, 31 Jul 2009 19:22:01

"Matthew O'Brien"

since you callback command is a string, H0 is NOT defined...
some of the solutions

% 1) ...,'callback', @(varargin) close(h0),...
% 2) com=sprintf('close(%f)',h0);
% ...,'callback',com,...

us