My code does not work properly

5 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Data 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