how to frequently update an edittext in matlab gui inside a timer function?

4 views (last 30 days)
Hai guys , As i mentioned i want to update an edittext on matlab gui on each call of the timer function. i am new to matlab and stuck with this issue. i tried something in my way using "set(handles.edit2,'String',sprintf('%d',a(1)));" ,it is working out side the timer function but when i put this inside the timer ,it shows an error . "Error while evaluating TimerFcn for timer 'timer-1'
Not enough input arguments." Please help..
function TmrFcn(src,event,handles)
global s;
fprintf(s,'y');
if(s.BytesAvailable ~= 0)
a = fscanf(s,'%d,%d,%d,%d,%d,%d');
a = a';
Labels = {'LIGHT','METHANE','TEMPERATURE','OXYGEN','H2S','CO'};
bar(a);
set(gca, 'XTick', 1:6, 'XTickLabel', Labels);
handles = guidata(handles);
set(handles.edit2,'String',sprintf('%d',a(1)));
end

Accepted Answer

Walter Roberson
Walter Roberson on 11 Jul 2015
Timer event functions are not automatically passed the handles structure, only the source and event.
When you define your timer callback, instead of saying that the callback is @TmrFcn use a callback of
@(src,event) TmrFcn(src,event,gcf,s)
and define
function TmrFcn(src,event,fignum,s)
fprintf(s,'y');
if(s.BytesAvailable ~= 0)
a = fscanf(s,'%d,%d,%d,%d,%d,%d');
a = a';
Labels = {'LIGHT','METHANE','TEMPERATURE','OXYGEN','H2S','CO'};
bar(a);
set(gca, 'XTick', 1:6, 'XTickLabel', Labels);
handles = guidata(fignum);
set(handles.edit2,'String',sprintf('%d',a(1)));
end
end

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!