Using Timer in startup.m
조회 수: 3 (최근 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!