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 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