My code does not work properly

3 vues (au cours des 30 derniers jours)
Behrooz Daneshian
Behrooz Daneshian le 5 Jan 2023
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 commentaire
Behrooz Daneshian
Behrooz Daneshian le 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);

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 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'

Plus de réponses (0)

Catégories

En savoir plus sur Data Acquisition Toolbox Supported Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by