Effacer les filtres
Effacer les filtres

function plus timer in background

24 vues (au cours des 30 derniers jours)
roberto
roberto le 25 Fév 2023
Commenté : roberto le 25 Fév 2023
Hello everybody
tks to Benjamin and Walter I run a webread function connected with a timer ,
I want to run a separate function, working in background, starting every 60 secs.
I've tried in some ways but didn't succed
this is the command:
longT=tbl(:,"dose");
LT=trenddecomp(longT);
figure(11);
plot(LT,"dose_LongTerm");
hold on;
plot(tbl,"dose");
hold off;
figure(10);
plot(LT,"dose_Seasonal")
  1 commentaire
roberto
roberto le 25 Fév 2023
Déplacé(e) : Walter Roberson le 25 Fév 2023
this is my attempt.
Ii put the above command in a script called LTdose, but running the function called "longseas", it gives me the following error:
"longseas
Error while evaluating TimerFcn for timer 'MyTimer'
Unrecognized function or variable 'tbl'."
but if I launch manually the script LTdose (even with run(LTdose) ), it works as usual
please a help, tks.
function [myTimer] = longseas
myTimer = timer('Name','MyTimer', ...
'Period',30, ...
'StartDelay',0, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
'TimerFcn',@myTimerCallback);
start(myTimer);
function myTimerCallback(hObject, eventdata)
run("LTdose");

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Fév 2023
When you run() a script inside of a function, the workspace of the script is the workspace of the function.
When you run() a script at the command line (and you are not stopped at the debugger), the workspace of the script is the base workspace.
The earlier discussion involved writing a timer not shown here, in which you wanted data read in every 60 seconds, and the final version of the code was assigning the data into the base workspace. If that is still what you are doing then in your script you should evalin('base', 'tbl') to retrieve tbl from the base workspace.
I am not clear as to why you want two separate 60 second timers, instead of having the callback for the first timer run the script?
  3 commentaires
Walter Roberson
Walter Roberson le 25 Fév 2023
function doStuff()
intervalInS=60;
everyNowAndThen = timer("Period",intervalInS,"ExecutionMode","fixedRate","TimerFcn",@refresh);
everyNowAndThen.start();
end
function refresh(~,~)
tbl = webread('https://api.=CSV');
assignin('base','tbl',tbl);
run("LTdose");
end
roberto
roberto le 25 Fév 2023
works like a charm, simply and efficient.
tks very much Walter.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by