Effacer les filtres
Effacer les filtres

adding to handles while loop is running

2 vues (au cours des 30 derniers jours)
Toke Søltoft
Toke Søltoft le 13 Fév 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?

Réponse acceptée

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

Plus de réponses (1)

Geoff Hayes
Geoff Hayes le 15 Fév 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).

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by