My code does not work properly

5 views (last 30 days)
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 Comment
Behrooz Daneshian
Behrooz Daneshian on 6 Jan 2023
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);

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 6 Jan 2023
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'

More Answers (0)

Categories

Find more on Data Acquisition Toolbox Supported Hardware 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!