automatic refresh webread data

2 ビュー (過去 30 日間)
roberto
roberto 2023 年 2 月 13 日
コメント済み: Jonas 2023 年 2 月 26 日
hello everybody
I have a webread data (XXX are confidential):
https://api.XXXXXXXX.com/time_series?apikey=XXXXXXXX&interval=1min&symbol=EUR/USD&timezone=Europe/Rome&end_date=2023-02-14 09:37:00&start_date=2023-02-13 09:37:00&format=CSV')
that I save as table in workspace and analyze it.
how can I get an automatic refresh every 1 minute to this url without copy and launch it manually on command window?
tks very much

回答 (4 件)

Jonas
Jonas 2023 年 2 月 13 日
編集済み: Jonas 2023 年 2 月 13 日
create a timer object, use a method for repeated execution and add the callback
EDIT:
e.g.
function doStuff()
intervalInS=10;
myData=[];
everyNowAndThen = timer("Period",intervalInS,"ExecutionMode","fixedRate","TimerFcn",@refresh);
everyNowAndThen.start();
function refresh(~,~)
myData=webread('https://de.mathworks.com/help/daq/troubleshooting-tips.html');
disp('next one')
end
end
  1 件のコメント
roberto
roberto 2023 年 2 月 21 日
編集済み: roberto 2023 年 2 月 21 日
with this little change the code works and refreshes on command window.
ans =
1000×5 table (answer on command window)
but the problem is that the workspace is empty..no ans in table format...
here the code (so far tks to Jonas. I've replaced his "display"):
function doStuff()
intervalInS=60;
myData=[];
everyNowAndThen = timer("Period",intervalInS,"ExecutionMode","fixedRate","TimerFcn",@refresh);
everyNowAndThen.start();
function refresh(~,~)
myData=webread('https://api......CSV');
webread('https://api........CSV')
end
end

サインインしてコメントする。


roberto
roberto 2023 年 2 月 13 日
Sorry, in this function where do I put 1 minute interval? Tks in advance
  1 件のコメント
Jonas
Jonas 2023 年 2 月 16 日
see variable intervalInS

サインインしてコメントする。


roberto
roberto 2023 年 2 月 14 日
what is function doStuff()?

roberto
roberto 2023 年 2 月 16 日
when I try your suggestion, this is the result:
function doStuff()
Error: Function definition are not supported in this context. Functions can only be created as local or nested functions in code files.
  1 件のコメント
Jonas
Jonas 2023 年 2 月 26 日
take ensure my code is working as intended, please copy y cody to a new .m file, save it and run it using
doStuff()
it looks like tried to paste my code to the command line

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by