Reading data from a different URL each iteration

조회 수: 2 (최근 30일)
Salma fathi
Salma fathi 2022년 10월 18일
댓글: Salma fathi 2022년 10월 24일
i am trying to read some data from a specific website, in this website there are some parametrs that we need to set to get the desired data, now reading the data for manually speccifed parametrs is an easy job. Now I am trying to automate this proceess such that the parametrs would be changed accordingly and the data for each set of parameters would be read directly without my interaction. to do that I have the follwoing URL that I am reading the data from
httpUrl = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=1997%2F01%2F01+00%3A00%3A00&toDate=1997%2F12%2F31+11%3A59%3A00";
where the parameters that need to be changed in the URL every time are the following
fromDate=1997%2F01%2F01+00%3A00%3A00 % where we need to change the year eveery time which is here =1997
which represent the starting date of the desired data and
toDate=1997%2F12%2F31+11%3A59%3A00 % where we need to change the year eveery time which is here =1997
which represent the ending date of the desired data. I strated with the follwoing lines but I am not sure how I can make the URL change every time and store all the read data in a table at the end.
httpUrl = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=1997%2F01%2F01+00%3A00%3A00&toDate=1997%2F12%2F31+11%3A59%3A00";
options = weboptions("ContentType", "text");
data = webread(httpUrl, options);
Iono= array2table(data);

채택된 답변

Jan
Jan 2022년 10월 18일
편집: Jan 2022년 10월 18일
F = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=%04d%%2F01%%2F01+00%%3A00%%3A00&toDate=%04d%%2F12%%2F31+11%%3A59%%3A00";
% % -> %%, then 1997 -> %04d
URL = sprintf(F, 1998, 1999)
URL = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE&DMUF=3000&fromDate=1998%2F01%2F01+00%3A00%3A00&toDate=1999%2F12%2F31+11%3A59%3A00"
  댓글 수: 3
Jan
Jan 2022년 10월 24일
F = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=%s&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=%04d%%2F01%%2F01+00%%3A00%%3A00&toDate=%04d%%2F12%%2F31+11%%3A59%%3A00";
URL = sprintf(F, 'QQQQQQ', 1998, 1999)
URL = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=QQQQQQ&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE&DMUF=3000&fromDate=1998%2F01%2F01+00%3A00%3A00&toDate=1999%2F12%2F31+11%3A59%3A00"
The format %04d prints a number with 4 digits and leading zeros. %s inserts a string or CHAR vector.
You find an exhaustive explanation of the formats at:
doc sprintf
Salma fathi
Salma fathi 2022년 10월 24일
Thank you so much that was so helpful.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by