How to pass a varying workspace variable to a function calles in a timer object?

2 views (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 14 May 2014

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!