Pausing the program for GUI

i have a code which does some calculation, then calls the GUI. In the GUI i have some options for user to select from. based on that answer, further calculation is done.
Function this = random(this)
...some calc
...some calc
...some calc
...some calc
GUI % calls the GUI
value = getappdata(0,'value') %gets the value from the GUI
...some calc
...some calc
end
the problem is when I compile, it calls the GUI and continues with the program. how do i make the program wait until a button is pressed in the GUI?

 采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-7-19

0 个投票

Use waitfor function

6 个评论

How exactly do i use this function. I have a apply button in my GUI, i want my main prgram to continue only when this button is pressed
Does GUI return its own handle? If so then you uiwait() on that handle. When you want to resume, either destroy that graphics object or else have your button call uiresume()
Don't think my GUI returns it's own handle. I'm trying with
waitfor(findobj('-regexp','Tag','Apply'))
where apply is the tag of the button. doesnt seem to work
How do you create the GUI? Surely all GUIs return their own handle?
I created them with GUIDE.
% --- Executes on button press in Apply.
function Apply_Callback(hObject, eventdata, handles)
% hObject handle to Apply (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value = get(handles.slider1,'Value');
setappdata(0,'final_value',value)
close()
this is my callback function of the button
But when you actually initialise the GUI, you can call it as e.g.
hGUI = MyGui;
to get the handle of the GUI, then use this with waitfor.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by