Using Timer in startup.m
1 次查看(过去 30 天)
显示 更早的评论
Hello,
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.
Regards,
Christian
0 个评论
回答(5 个)
Daniel Shub
2012-6-21
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
$ matlab
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?
EDIT
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?');
pause(10);
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.
0 个评论
Malcolm Lidierth
2012-6-22
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.
E,g,
props=java.lang.System.getProperties();
props.put(.....)
works, but
java.lang.System.getProperties().put(....)
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.
3 个评论
Malcolm Lidierth
2012-6-22
@Daniel
I would not call it a bug. That startup.m runs "during" startup is documented so it seems reasonable to expect the system not to be fully loaded when it runs.
Daniel Shub
2012-6-22
It seems like we are just left to guess what functions are allowed in startup.m and matlabrc.m.
Christian
2012-6-21
1 个评论
Daniel Shub
2012-6-21
This really should be a comment to my answer and /or an edit to the question instead of a new answer.. If my answer was helpful, you should consider voting for it. Some code would help figure out what you are doing wrong. Are you sure startup.m is being run?
Christian
2012-6-21
2 个评论
Daniel Shub
2012-6-21
It looks like a bug to me. See the edit to my answer. I can think of two easy work arounds: use the -r option or have the first callback of the timer launch do_some_calculations.
Jan
2012-6-21
TIMER requires Java. Although the documentation states, that -nodekstop does start Java, it is worth to check this by javachk('jvm').
3 个评论
Jan
2012-6-22
I agree that -nodesktop is not the reason. I suggested to check, if Java is available in both cases.
Daniel Shub
2012-6-22
Adding javachk('jvm') to startup.m does not cause problems. However, if MATLAB and Java are not fully initialized, it is not clear if JAVACHK actually works correctly. Running javachk('jvm') after starting up with the -nodesktop option, does not produce an error message.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!