필터 지우기
필터 지우기

adding to handles while loop is running

조회 수: 2 (최근 30일)
Toke Søltoft
Toke Søltoft 2015년 2월 13일
답변: Toke Søltoft 2015년 2월 19일
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?

채택된 답변

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

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 2월 15일
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).

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by