How to skip years with no data when reading the data from a website

3 vues (au cours des 30 derniers jours)
Salma fathi
Salma fathi le 30 Oct 2022
Commenté : Salma fathi le 31 Oct 2022
I am trying to read some data from a website in the following manner:
  1. 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,

Réponse acceptée

Chris
Chris le 30 Oct 2022
You could use continue to move to the next iteration of the for loop.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by