Borrar filtros
Borrar filtros

adding to handles while loop is running

2 visualizaciones (últimos 30 días)
Toke Søltoft
Toke Søltoft el 13 de Feb. de 2015
Respondida: Toke Søltoft el 19 de Feb. de 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?

Respuesta aceptada

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

Más respuestas (1)

Geoff Hayes
Geoff Hayes el 15 de Feb. de 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).

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by