How to skip years with no data when reading the data from a website
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Salma fathi
el 30 de Oct. de 2022
Comentada: Salma fathi
el 31 de Oct. de 2022
I am trying to read some data from a website in the following manner:
- we have multiple stations to read data from and for each station we need to read the data from 2007 to 2022, but some stations they do not have data for this whole period of time, so we need to make our code able to skip these years with no data. it might be staright forward to do but I dont seem to know how to implement it, Here is what I started doing
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";
stnName=["JI91J" "NV355" "MO155" "KS759" "MA560" "TZ362" "YA462" "GA762" "EI764" "CO764" "SH266" "ZH466" "SMJ67" "NO369" "TR169" "NDA81"];
strY=2007; %the starting year
EndY=2022 ; % the ending year
numOfYears=(EndY-strY)+1;
for qq=1:legth(stnName) %this loop is to go through the stations
for kk=1:numOfYears %this loop is to go through the years
jj=kk+strY-1;
fid = sprintf(F, jj,jj);
data = webread(fid);
if length(data)==303 %this when the website will have no data to show
%here I have the issue on if the website had no data for a certain year
%then we go to the next year and check.
jj=jj+1;
fid = sprintf(F,stnName{qq}, jj,jj);
data = webread(fid);
else %This is the desired way of reading the data for us
C = textscan(data, '%{uuuu-MM-dd''T''HH:mm:ss.SSS''Z}D %s %s %*s %s %*s %s %*s %s %*s %s %*s %s %*s %s %*s', 'Whitespace',' ' , 'CommentStyle' , '#');
T= table(C{:});
end
end
end
% many thanks in advance,
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!