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

23 次查看(过去 30 天)
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.

采纳的回答

David Sanchez
David Sanchez 2013-8-19
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

更多回答(1 个)

Image Analyst
Image Analyst 2013-8-19
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.

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by