Declan - do you really mean you want to update the variable every tenth of a millisecond? Because that implies that the period of the timer would need to be 0.0001 which seems to be unsupported (see period description) as the minimum allowed value is one millisecond (0.001). If one millisecond is sufficient, then you could nest your timer callback within your main function so that the timer callback has access to the variable t. Perhaps something like
function myTimerTest
t = 0;
cumulativeTimerCallbackStart = 0;
periodSec = 0.001;
numTasksToExecute = 100;
myTimer = timer('Name','MyTimer', ...
'StartDelay', periodSec, ...
'ExecutionMode','fixedRate', ...
'TimerFcn',{@timerCallback}, ...
'TasksToExecute', numTasksToExecute, ...
'StartFcn', @startCallback, ...
'StopFcn', @stopCallback, ...
'Period', periodSec);
start(myTimer);
function timerCallback(hObject, eventdata)
t = toc(cumulativeTimerCallbackStart);
end
function startCallback(hObject, eventdata)
cumulativeTimerCallbackStart = tic;
end
function stopCallback(hObject, eventdata)
fprintf('Elapsed time after %d iterations: %.4f\n', numTasksToExecute, t);
end
where tic and toc are used to get the elapsed time between each timer callback and so "should" be a decent t. Note that the smaller the period, the greater the delay introduced between each callback firing (so you won't necessarily see the callback fire every 1 ms if that is what you have set the period to be).
