How to get daily temperatures of past 30 years for a given location from NOAA online database

8 ビュー (過去 30 日間)
Hi all and Merry Christmas.
I want to download average daily temperatures of the past 30 years for a given location from NOAA database. I am given a base URL as below:
and also I received a token from NOAA website that I need to use that to access the data. According to the NOAA instructions, assigned token is required to use these queries and must be in the header. Can anyone tell me how to set the token in the header? This is the first time I want to do that.(please visit the below link for further infirmation)
  5 件のコメント
Behrooz Daneshian
Behrooz Daneshian 2022 年 12 月 26 日
Exactly, and the endpoints are to fetch specific data we want.
the cyclist
the cyclist 2023 年 1 月 20 日
This problem was already solved, but I wanted to add some info I stumbled across later. I learned about a site/utility that will convert curl commands to MATLAB (and many other languages).
For clarity, I am talking about cURL, the library and unix command line tool for transferring data over a network -- not the mathematical curl operator.

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

採用された回答

the cyclist
the cyclist 2022 年 12 月 26 日
Here is how you can do this using webread:
myToken = 'PUT_YOUR_TOKEN_BETWEEN_THESE_QUOTES';
myURL = 'https://www.ncei.noaa.gov/cdo-web/api/v2/locations/FIPS:37';
opt = weboptions('KeyName','token','KeyValue',myToken);
data = webread(myURL,opt);
  15 件のコメント
Behrooz Daneshian
Behrooz Daneshian 2022 年 12 月 27 日
I can run it .Thank you very much for taking time on my questions. I learned a lot from you.
the cyclist
the cyclist 2022 年 12 月 27 日
I'm glad it worked out for you

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

その他の回答 (1 件)

the cyclist
the cyclist 2022 年 12 月 26 日
編集済み: the cyclist 2022 年 12 月 26 日
Here is an example that worked for me (using my own token, of course).
It uses MATLAB's system function to call the system's curl function.
myToken = 'PUT_YOUR_TOKEN_BETWEEN_THESE_QUOTES';
myURL = 'https://www.ncei.noaa.gov/cdo-web/api/v2/locations/FIPS:37';
cmdString = ['curl -H ''token:',myToken,''' ''',myURL,''''];
[status, curlOutput] = system(cmdString)
The trickiest part is actually constructing the string to send out to the system, because the string itself has quotes in it. There is probably a more elegant way, or even a MATLAB function that will do this more directly, but I know this solution works.
  7 件のコメント
the cyclist
the cyclist 2022 年 12 月 26 日
編集済み: the cyclist 2022 年 12 月 26 日
@Image Analyst, "curl" is unix utility for pulling URL info. (Some web searching suggests that it is, in fact, shipped with Windows. But, I can't really help there.) Given the error that @Behrooz Daneshian reported directly from the command line, I'm guessing we're not going to get that to work via MATLAB.
I agree that webread or websave is promising. Probably one just needs to figure out how to send the token along with the URL. I tried a couple simple Name-Value input combinations, but did not get it to work (yet).
the cyclist
the cyclist 2022 年 12 月 26 日
Just after I posted the above comment, I figured out (well, found out) how to do this. See my other answer.

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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by