Displaying Timer Function in Graph

17 ビュー (過去 30 日間)
sufyan patel
sufyan patel 2017 年 2 月 22 日
編集済み: Geoff Hayes 2017 年 2 月 25 日
Hi,
I have created a timer function, which after every second displays EEG data coming through.
I want this to be displayed in a graph not in the command window. How is this possible? Currently it displays the text in the command window
The code is attached
  1 件のコメント
Geoff Hayes
Geoff Hayes 2017 年 2 月 25 日
編集済み: Geoff Hayes 2017 年 2 月 25 日
sufyan - your code is simply
plot(handles.graph, handles.data, handles.timer)
t = timer('TimerFcn',{@timerCallback,handles},...
'Period',2,'ExecutionMode','fixedRate');
start(t)
function timerCallback(myTimerObj, ~, handles)
size(handles.data)
handles.timer = t
and so it is unclear how it is all related. Where is the EEG data coming from? Is it the handles.data? Note that you don't want to be passing in handles as an input to the timer callback since this is a copy of the handles structure and so won't have any of its fields updated. Instead you will want to pass in the handle to the figure so that you can get the handles from that.

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

採用された回答

Geoff Hayes
Geoff Hayes 2017 年 2 月 25 日
編集済み: Geoff Hayes 2017 年 2 月 25 日
sufyan - suppose that your timer starts when you press the start button in your GUI. The pushbutton callback would look something like
function start_Callback(hObject, eventdata, handles)
handles.timer = timer('Name','MyTimer', ...
'Period',1.0, ...
'StartDelay',0, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
'TimerFcn',{@timerCallback,handles.figure1});
guidata(hObject,handles);
start(handles.timer);
The above timer will fire (roughly) every second. Note how we pass the GUI figure handle as an input to the timerCallback function. This is necessary so that we can access the handles structure (from there) to (potentially) update the axes with new data. The callback can be defined as
function [] = timerCallback(~,~,guiHandle)
if ~isempty(guiHandle)
% get the handles
handles = guidata(guiHandle);
if ~isempty(handles)
% use EEG handles.data (?) to update the axes
% if new data, then update the axes
end
end
In the above, we get the handles structure using guihandles so that we can get the current set of data in the axes control. In your stop button callback, you would then stop the timer
function stop_Callback(hObject, eventdata, handles)
if isfield(handles, 'timer')
stop(handles.timer);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by