How to utilize an existing API to download weather data and use it for calculations in a MATLAB script?

3 ビュー (過去 30 日間)
I want to create a script that can download files from the National Solar Radiation Database using their API (I have an API Key) and convert them to tables, cells, or structures in the workspace so that I can use the data for calculations in MATLAB. (I am designing a solar power system, and want the irradiance data to create an accurate estimate of how much power I can expect specific panels to produce in that location. The data also includes things like temperature, windpseed etc. which are extremely useful for designing the system). The only purpose of this question is to figure out how to pull the data using the API and store it in a structure, cell array, or table.
This link shows an example of the API, and it does achieve my goal of entering coordinates to recieve weather data from the nearest station. I've read some documentation on the "webread" function, but I'm still shaky on how to achieve this in matlab. The only output formats from the API are JSON and XML. I imagine that XLM could be read with "xlmread" function according to the documentation, but I haven't worked with API's enough to set up an example and verify. I believe I have every toolbox for the R2020a release.


millercommamatt 2022 年 9 月 8 日
編集済み: millercommamatt 2022 年 9 月 8 日
Build a string that is structured like this and use it as the input to webread:
Use the information at the link you provided to specify the input variables you want.
%% INPUTS (all are strings/char)
api_key = 'DEMO_KEY';
lat = '40';
lon = '-150';
radius = '32';
%% fetch the data
api_base = '';
data_out_struct = webread(...
[ api_base '&api_key=' api_key '&lat=' lat '&lon=' lon '&radius=' radius]...
); % you'll get a struct out
  1 件のコメント
Craig Atkinson
Craig Atkinson 2022 年 9 月 10 日
I figured it was going to be more simple than I thought, thank you! I can work with this


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by