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

回答(1 个)

Walter Roberson
Walter Roberson 2014-5-14

类别

Help CenterFile Exchange 中查找有关 Handle Classes 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by