フィルターのクリア

Passing arguments into timer stopFCN in gui

1 回表示 (過去 30 日間)
Quentin
Quentin 2014 年 3 月 3 日
コメント済み: Walter Roberson 2014 年 3 月 3 日
Hello all,
I'm having a little confusion on using a timer in data acquisition GUI. I was hoping someone could give me a little help with the syntax. Basically I have code that acquires data and looks like this
function acquireButton_Callback(hObject, eventdata, handles)
sweepsPerTrigger = str2double(get(handles.editSweepsPerTrig, 'String'));
inter_stimulus_interval = str2double(get(handles.editISI, 'String'));
acquisitionTimer = timer;
acquisitionTimer.ExecutionMode = 'fixedRate';
acquisitionTimer.TasksToExecute = sweepsPerTrigger;
acquisitionTimer.Period = inter_stimulus_interval;
acquisitionTimer.StopFcn = @acquisitionTimerCleanup; %(acquisitionTimer, hObject, eventdata, handles);
acquisitionTimer.TimerFcn = @(myTimerObj, thisEvent)startAcquisition(hObject, eventdata, handles);
start(acquisitionTimer);
function acquisitionTimerCleanup(acquisitionTimer,~)
disp('Done Acquiring');
delete(acquisitionTimer);
set(handles.acquireButton, 'String', 'Acquire');
set(handles.acquireButton, 'BackgroundColor', 'g');
The issue that I have is that the stopFCN cannot access the handles.acquireButton to change the string and background color. How do I go about passing "hObject, eventdata, handles" to the stopFCN so that it can modify them.
Thank you tremendously for the help. Quentin

採用された回答

Quentin
Quentin 2014 年 3 月 3 日
Thanks Walter. I got an error message when I tried this. It said "Error while evaluating StopFcn for timer 'timer-1'. I'm assuming I need to modify the line
function acquisitionTimerCleanup(acquisitionTimer,~)
Is that correct? I'm not exactly what the ~ means in this case. Also was wondering if you describe why you used the @(src, evt) . I've never quite been able to figure out what the @ symbol means in these callback functions.
Thanks Walter.
  1 件のコメント
Walter Roberson
Walter Roberson 2014 年 3 月 3 日
function acquisitionTimerCleanup(acquisitionTimer, evt, handles)

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 3 月 3 日
Provided that all you need is the button handles and they are not going to change after you configure the timer, then:
acquisitionTimer.StopFcn = @(src, evt) acquisitionTimerCleanup(src, evt, handles);
If you make any changes to the handles structure between the time that you configure the timer and the time the stop function runs, then the above will not work.

カテゴリ

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