Filter löschen
Filter löschen

adding to handles while loop is running

2 Ansichten (letzte 30 Tage)
Toke Søltoft
Toke Søltoft am 13 Feb. 2015
Beantwortet: Toke Søltoft am 19 Feb. 2015
I have a while loop running for long time which uses different handles. While it is running I want to be able to press a button in GUI which then adds a number into handles. How is this possible?
timeNow = datetime;
handles.depth_stoptime = [handles.sort.depthtime; datestr(timeNow,'YYYY-mm-dd HH:MM:ss')];
guidata(hObject, handles);
This doesn't work, since the handles in the loop doesn't get this update.
Is the solution to use
global depth_stoptime
instead?

Akzeptierte Antwort

Toke Søltoft
Toke Søltoft am 19 Feb. 2015
Well, I used global variables and it works fine. I tried with the pause, but it didnt help.

Weitere Antworten (1)

Geoff Hayes
Geoff Hayes am 15 Feb. 2015
Toke - you probably need to add a pause statement to you while loop so that it can be interrupted by the pressing of the pushbutton. See callback sequencing and interruption for details. If your pushbutton callback is something like
function pushbutton1_Callback(hObject, eventdata, handles)
timeNow = datetime;
handles.depth_stoptime = [handles.sort.depthtime; datestr(timeNow,'YYYY-mm-dd HH:MM:ss')];
guidata(hObject, handles);
then the code in which you have the while loop will need to be something similar to
while someConditionIsTrue
% do stuff
% pause to allow other functions to interrupt this one
pause(0.01);
% get the latest handles data
handles = guidata(hObject);
end
The above assumes that the while code is in some callback that has access to hObject so that we can get the latest version of handles (we have to do this else we will only be using the local copy of handles at the time at which this function was called and so won't get the updated depth_stoptime).

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by