Using Timer in startup.m
4 views (last 30 days)
is it expected behavior that it is not possible to use timer objects in the startup.m? I have seen that in case I include a call to a script in startup.m, where the script creates and starts a timer, obviously the TimerFcn callback is never executed. But there is also no error when the timer is created or started. On the other hand, when I use the -r command line option and pass the name of the script, the timer works as expected. I haven't found any hint in the documentation about this issue. I'm using R2010b 64bit on Linux.
Daniel Shub on 21 Jun 2012
It works for me in Linux. From the command line (note that this will overwrite the startup.m file in the current directory)
$ echo "start(timer('TimerFcn', 'why', 'Period', 1.0, 'ExecutionMode', 'fixedDelay'));" > startup.m
After a few seconds I have:
The bald and not excessively bald and not excessively smart hamster obeyed a terrified and not excessively terrified hamster.
To fool the tall good and smart system manager.
The rich rich and tall and good system manager suggested it.
He wanted it that way.
The programmer suggested it.
Barney suggested it.
To please a very terrified and smart and tall engineer.
The tall system manager obeyed some engineer.
To satisfy some programmer.
Damian wanted it that way.
Can you rephrase that?
The above looks like it works, but it doesn't really. A slight modification shows the failure:
$ echo "start(timer('TimerFcn', 'why', 'Period', 1.0, 'ExecutionMode', 'fixedDelay')); disp('Will the timer fire during a 10 second pause?'); pause(10); disp('Now the pause is over?');" > startup.m
This creates the following startup.m
start(timer('TimerFcn', 'why', 'Period', 1.0, 'ExecutionMode', 'fixedDelay'));
disp('Will the timer fire during a 10 second pause?');
disp('Now the pause is over?');
There should be answers to "why" during the pause, but there are not. It appears that timer objects do not execute until after startup.m (more likely matlabrc.m) exits.
I am not aware of this being documented and would guess it is a bug.
Malcolm Lidierth on 22 Jun 2012
STARTUP.m called from MATLABRC.m MATLAB during startup. Any code specified with -r gets called after startup. Not all commands that are valid after startup can be called from startup.m.
does not giving
Static method or constructor invocations cannot be indexed.
Do not follow the call to the static method or constructor with
any additional indexing or dot references.