Running Script using Timer
이전 댓글 표시
I am trying to use Timer function to run a script at pre-specified interval (30 seconds). However, most of the examples, including MATLAB help, is directed towards using callback functions. However, when I tried something similar to use the script to run using timer, I get an error message.
Specifically, I am using Bloomberg's data function to get real time data and would like to simply revoke that Bloomberg function every 30 seconds.
Any help would be sincerely appreciated. Please feel free to ask question, if I am not being clear.
Thank you,
답변 (2개)
per isakson
2013년 12월 5일
편집: per isakson
2013년 12월 6일
The trick is to use an anonymous function. Try
>> my_timer_test
2013-12-05 22:09:31
2013-12-05 22:09:43
2013-12-05 22:09:55
2013-12-05 22:10:07
where
%%my_timer_test
tmr = timer ...
( 'Name' , 'my_timer' ...
, 'TimerFcn' , @(x,y) my_script ...
, 'BusyMode' , 'drop' ...
, 'ExecutionMode' , 'fixedDelay' ...
, 'Period' , 12 ...
, 'StartDelay' , 1 ...
);
start( tmr )
and
%%my_script
disp( datestr( now, 31 ) )
are two script files
댓글 수: 8
KKR
2013년 12월 6일
편집: per isakson
2016년 9월 30일
per isakson
2013년 12월 6일
Try to use the {}Code button. It makes it easier to read the code.
per isakson
2013년 12월 6일
편집: per isakson
2013년 12월 6일
It is obviously not a good idea to use a script in the value of the property, TimerFcn. See Variables in Nested and Anonymous Functions and note especially: "Calling a MATLAB script that creates a variable". The property name contains the letters Fcn for a reason.
Thus, convert your script to a function.
Alfonso Nieto-Castanon
2013년 12월 7일
I imagine you probably want to run your script on the base workspace (as if you run it on the Matlab command window), right?.
If that is the case, in the example above simply change the portion that reads:
@(x,y)my_script
into:
@(varargin)evalin('base','my_script');
Hope this helps
KKR
2013년 12월 19일
per isakson
2013년 12월 19일
Matlab is not always helpful! I guess the Blomberg page contained something else than digits in a field where "your" script expected digits.
See:
KKR
2013년 12월 19일
per isakson
2013년 12월 19일
What does "it" refer to? Isn't it a case for ordinary debugging? http://undocumentedmatlab.com/ may have something useful to say on debugging Java code.
카테고리
도움말 센터 및 File Exchange에서 Platform and License에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!