フィルターのクリア

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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by