Using a pushbutton in MATLAB GUI as a button to continue?

26 views (last 30 days)
Hi, I have 2 pushbuttons. With one of them I call a specific function. eg: Main_function(...,...,...).
Now within this Main_function at some points I need the user to press continue. (The user has to change some equipment then continue the work) Previously I used input('') and the user should have just push enter or whatever to continue the function.
Right now I want the second pushbutton to do this, but I don't know how.
my idea was to put a loop like this:
push=0
while push==0
puase(0.1);
end and pushing the button change the push=1, but I can't do that.
Note that I have access to the handles in the called function.

Accepted Answer

David Sanchez
David Sanchez on 19 Aug 2013
Add a while loop with nothing inside:
while (~push)
% do nothing until push == 1. Push has to be global, it changes when the pushbutton is pushed
end

More Answers (1)

Image Analyst
Image Analyst on 19 Aug 2013
I would not do it like either of you. I think the best way, and what I usually see as recommended, is to wrap a call to msgbox in uiwait. Like this:
uiwait(msgbox('Now, change the equipment, then click OK to continue'));
You can do what I do, and that is to make a separate function called msgboxw (in a separate msgboxw.m file somewhere on your path) and then just call that instead of msgbox:
function msgboxw(message)
uiwait(msgbox(message));
To use
msgboxw('Click OK to continue');
Or, to give the user more flexibility,
promptMessage = sprintf('Do you want to Continue processing,\nor Cancel to abort processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return; % or break, if you're in a loop
end
This has the same effect as msgboxw() except that it allows the user to bail out if they want.

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!