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

roberto
roberto 2023년 2월 25일
이동: Walter Roberson 2023년 2월 25일
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");

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2023년 2월 25일

0 개 추천

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

roberto
roberto 2023년 2월 25일
편집: roberto 2023년 2월 25일
yes you are right I should also insert this second script into the first function with timer . I've tried but didn't succed. so how should I modify the first function (written below)? Thank you very much
function doStuff()
intervalInS=60;
everyNowAndThen = timer("Period",intervalInS,"ExecutionMode","fixedRate","TimerFcn",@refresh);
everyNowAndThen.start();
function refresh(~,~)
assignin('base','tbl',webread('https://api.=CSV'))
end
end
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 2023년 2월 25일
works like a charm, simply and efficient.
tks very much Walter.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

질문:

2023년 2월 25일

댓글:

2023년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by