How to create a GUI inside a function in Matlab?
- by Paperflyer
Is there a possibility to write a GUI from inside a function?
The Problem is: The callback of all GUI-functions work in the global workspace. But functions have their own workspace and can not access variables in the global workspace. Is there a possibility to make the GUI-functions use the workspace of the function?
function myvar = myfunc()
myvar = true;
h_fig = figure;
% create a useless button
uicontrol( h_fig, 'style', 'pushbutton', ...
'string', 'clickme', ...
'callback', 'myvar = false' );
% wait for the button to be pressed
while myvar
pause( 0.2 );
end
close( h_fig );
disp( 'this will never be displayed' );
end
This event-loop will run indefinitely, since the callback will not modify myvar in the function. Instead it will create a new myvar in the global workspace.