My code does not work properly

3 ビュー (過去 30 日間)
Behrooz Daneshian
Behrooz Daneshian 2023 年 1 月 5 日
回答済み: the cyclist 2023 年 1 月 6 日
Hi all,
Using the code below I am supposed to extract daily temperature from NOAA database for a desired year range(e.g. 2006 to 2010). When I examined the created table(annualTemperatureData) in which dates as well as corresponding tempretaures exist, I realized that when a year is changing(e.g. form the date of '2006-12-31' to '2007-01-01'), the next year does not start from January 1,instead it begins with 28 February! I checked the code several times but I do not know why I do not get the right answer. Can anyone help me with this regard?
getdata function is from the MATLAB Interface for NOAA Data. Please see this link: https://www.mathworks.com/matlabcentral/fileexchange/119213-matlab-interface-for-noaa-data
clear
close all
clc
n = noaa("dHsFHwpJjKwcKvgEWfcwoUmzbqYrdGCc");
annualTemperatureData = [];
for y = 2006:2010
annualTemperatureData = [annualTemperatureData;getdata(n,"GHCND", ...
datetime(strcat(num2str(y),"-01-01")), ...
datetime(strcat(num2str(y),"-12-31")), ...
stationid = "GHCND:USW00063857", ...
datatypeid = "TAVG", ...
datatypeid = "TMIN", ...
datatypeid = "TMAX", ...
limit = 1000, ...
units = "standard")];
end
  1 件のコメント
Behrooz Daneshian
Behrooz Daneshian 2023 年 1 月 6 日
Even if we try the code below just for a one year(without using getdata function), data does not start from January!
myToken = "dHsFHwpJjKwcKvgEWfcwoUmzbqYrdGCc";
Initial_URL = "https://www.ncei.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND&stationid=GHCND:SPE00119783&startdate=2006-01-01&enddate=2010-12-31&limit=1000&datatypeid=TAVG";
opt = weboptions('KeyName','token','KeyValue',myToken);
Data=webread(Initial_URL,opt);

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

採用された回答

the cyclist
the cyclist 2023 年 1 月 6 日
My best guess is that this is a problem at the source, and not with your code. I used curl directly against the API (as we have discussed your previous questions), for a smaller segment of data, and fails to pull the same time period.
curl -H 'token:dHsFHwpJjKwcKvgEWfcwoUmzbqYrdGCc' 'https://www.ncei.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND&stationid=GHCND:USW00063857&datatypeid=TMIN,TMAX&startdate=2006-01-01&enddate=2006-03-31'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Acquisition Toolbox Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by