필터 지우기
필터 지우기

MATLAB gui timer function callback problem

조회 수: 2 (최근 30일)
Shraddha
Shraddha 2014년 5월 20일
답변: RZM 2016년 9월 20일
Hi,
I'm trying to use a timer in my matlab GUI that calls a function. Passing the handle for the function is causing me issues. Can someone help me with where I'm going wrong in this code?
I'm getting the following error:
Error while evaluating TimerFcn for timer 'timer-1'
Not enough input arguments.
The timer is initialized in the open function for the GUI like so:
function Control_Window_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Control_Window (see VARARGIN)
% Choose default command line output for Control_Window
handles.output = hObject;
guidata(hObject, handles);
handles = guidata(hObject);
sda = handles.auto_read;
autoread_timer = timer('TimerFcn', {@(hObject, eventdata, handles)auto_read_Callback}, 'Period', 1,'ExecutionMode', 'fixedRate');
start(autoread_timer);
And the function that is accessed with the callback is:
function auto_read_Callback(hObject, eventdata, handles)
% hObject handle to auto_read (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.auto_read,'BackgroundColor',[0 1 0]);
set(handles.tabA,'BackgroundColor',[0.7 0.78 1]);
set(handles.tabB,'BackgroundColor',[0.7 0.78 1]);
set(handles.tabC,'BackgroundColor',[0.7 0.78 1]);
set(handles.tabD,'BackgroundColor',[0.7 0.78 1]);
if (get(hObject,'Value'))
data=get(handles.Table1,'data');
for x=1:size(data)
if data{x,4}==1
temp = data{x,1};
string1 = 'struct.';
string2 = strcat(string1,temp);
actualvalue = evalin('base', string2);
data{x,5}=actualvalue;
set(handles.Table1,'data',data)
else
;
end
end
end
set(handles.auto_read,'BackgroundColor',[0.831 0.816 0.784]) ;
Any help would be appreciated

답변 (1개)

RZM
RZM 2016년 9월 20일
You can use
function auto_read_Callback(obj,event,hObject,eventdata)
handles = guidata(hObject);
instead of
function auto_read_Callback(hObject, eventdata, handles)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by