
114 Accelerating MATLAB
®
Performance
Here is a sample implementation of this mechanism. First initialize the timeout ag:
% Initialize the global timeout flag
global timeoutFlag
timeoutFlag = false;
Next, set up a single-shot timer to trigger the timeout event:
% Create and start the separate single-shot timeout timer thread
hTimer = timer('TimerFcn',@timeoutEventFunc, 'StartDelay',timeout);
start(hTimer);
where timeoutEventFunc is dened to raise timeoutFlag, as follows:
% Function to raise the timeout flag
function timeoutEventFunc(hTimer,eventData)
global timeoutFlag
timeoutFlag = true;
end
Finally, in our main processing loop, we ...