Hi Andrew, You can make a small uicontrol object like a pushbutton and use delete(gcbf) in callback. Check the code given below.
function A
f=figure;
p=uicontrol('Parent',f,'Style','pushbutton','Callback',{@C},'Position',[50 50 100 100]);
B(f);
end
function B(f)
e=uicontrol('Parent',f,'Style','edit','String','0');
while(ishandle(f))
e.String=num2str(randn);
pause(0.3);
drawnow();
end
end
function C(~,~)
delete(gcbf);
end
Hope this helps. MATLAB does not have a function that scans for keyboard activity without interrupting the event stream.
However, if your program involves a figure window, you can utilize the ‘KeyPressFcn’ property. Refer to this link if you want to know how to do that:-
https://www.mathworks.com/matlabcentral/answers/100980-how-do-i-write-a-loop-in-matlab-that-continues-until-the-user-presses-any-key
Best Answer