How to pass a varying workspace variable to a function calles in a timer object?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 14 May 2014
Shared variables or have the timer fetch the updated value.
0 Comments
See Also
Categories
Find more on Handle Classes 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!