From: Steven Keith on
I have implemented a timer within a GUI, and I want it to use its own output. If I store function output in a GUI display field, I can retrieve the updated value. If I store function output as a variable in the handles structure, each timer iteration sees only the original value. Fine for one variable, but I want to make a more comprehensive function.

Any thoughts?

code within GUI----------------------------
function togglebutton1_Callback(hObject, eventdata, handles)

if get(hObject,'Value')
% reset to zero when restarting timer
handles.writeRow=0;
set(handles.edit1,'String',num2str(0))
guidata(hObject, handles);

handles.Timer = timer( 'Period', 2,...
'TasksToExecute',10,...
'ExecutionMode','fixedRate',...
'ErrorFcn','display(''error'')');
handles.Timer.TimerFcn = {@myfunc1,handles};
guidata(hObject, handles);

start(handles.Timer)

else
stop(handles.Timer)
delete(handles.Timer)
end

function myfunc1(timer, event, handles)

% this value does not update
handles.writeRow
% but this value does
writeRow = str2num(get(handles.edit1,'String'))

writeRow = writeRow+1;
handles.writeRow = writeRow;
set(handles.edit1,'String',num2str(writeRow))
guidata(handles.output, handles);