Filter löschen
Filter löschen

MATLAB gui timer function callback problem

3 Ansichten (letzte 30 Tage)
Shraddha
Shraddha am 20 Mai 2014
Beantwortet: RZM am 20 Sep. 2016
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

Antworten (1)

RZM
RZM am 20 Sep. 2016
You can use
function auto_read_Callback(obj,event,hObject,eventdata)
handles = guidata(hObject);
instead of
function auto_read_Callback(hObject, eventdata, handles)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by