MATLAB: Does a TimerFcn fail to operate once another function is called

timertimerfcn

I have created a timer to update a waitbar while another funciton is called to read in a data file. The purpose is to show the end user of my GUI that the process is running.
The function that reads in the data file is a mex file and I do not have the ability to update the waitbar directly from it.
I have placed a pause(10) command before the function call to the mex file and the timerfcn works great for those 10 seconds then ceases while the mex file function runs.
Any ideas or reasons why this would happen or ways to fix it would be greatly appreciated.
Thanks

Best Answer

Timers work at the MATLAB level. If MATLAB is not in control, such as if a mex routine has been called (and that routine does not request drawnow()) then the timers cannot work until MATLAB gains control again.
If you have the Parallel Computing Toolkit, you could have the waitbar in one thread and the call to the mex routine in another thread, and you could have the second thread notify the first thread when there was some news about the status of the second thread.
However, that arrangement would not, you will find, be of any benefit in updating the waitbar itself: as long as the mex routine is running, you cannot know how far it has proceeded, cannot know whether perhaps the mex routine got into an infinite loop or got stuck waiting for I/O or waiting for an interrupt that never arrived or got swapped out so that Windows could fly the logo around the screensaver. 15 seconds without return could mean 15 seconds of progress but it might mean no progress at all.
There is, though, a point in waiting the user to be able to cancel an active thread that might happen to be in a mex routine; there is also a point in having "watchdog times" that detect that Something Is Wrong.
The only clean way to force MATLAB activity to top that I have noticed as yet, is to use the Parallel Computing batch() facility, which has a cancel() operation (though I do not know if that can stop something that is already running.)
Related Question