How to pass a varying workspace variable to a function calles in a timer object?
3 次查看(过去 30 天)
显示 更早的评论
Hello, I have a callback function that I would like to execute every 10 seconds. What I wish to do is pass it a varying variable from the workspace that can be changed through a GUI. Is this possible?
global iNumberOfPeople
iNumberOfPeople = 0;
simple_GUI
Timer = timer;
Timer.UserData = iNumberOfPeople;
Timer.StartFcn = @OnStart;
Timer.StopFcn = @OnExit;
Timer.Period = 10;
Timer.TimerFcn = @UploadTxt;
Timer.TasksToExecute = 5;
Timer.ExecutionMode = 'fixedRate';
%
start(Timer);
function UploadTxt(mTimer, ~ )
fCurrentJulianDate = Time.GetCurrentJulianDate;
iNumberOfPeople = mTimer.UserData;
fileID = fopen('NumberOfPeopleMasterThesisRoom.txt', 'a+');
fprintf(fileID,'%12s \t\t\t\t %3.2f\n',fCurrentJulianDate, iNumberOfPeople);
fclose(fileID);
Thank you for your help. LF
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Handle Classes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!