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

2 ビュー (過去 30 日間)
Salma fathi
Salma fathi 2022 年 10 月 30 日
コメント済み: Salma fathi 2022 年 10 月 31 日
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 = ",foF1,foE,foEs,hmF2,hmF1,hmE" + ...
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
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
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.
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{:});
% many thanks in advance,


Chris 2022 年 10 月 30 日
You could use continue to move to the next iteration of the for loop.
  1 件のコメント
Salma fathi
Salma fathi 2022 年 10 月 31 日
Thamk you.


その他の回答 (0 件)


Find more on Scope Variables and Generate Names in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by