read Information from a web
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, I got this code to run all the information from a page but when I run it on matlab I get errors. The code is:
"descripcion" : "exito",
"estado" : 200,
"datos" = "https://opendata.aemet.es/opendata/sh/79adac19",
"metadatos" : "https://opendata.aemet.es/opendata/sh/b3aa9d28"
in the first link I got all the information I want how can I get it??
댓글 수: 2
Image Analyst
2021년 9월 28일
Where did you get that code? It's not MATLAB code. Just putting that into a script will not cause it to "read" or "run" "all the information from a page". You probably need to call webread() or something. Please attach your script (m-file) if you have one.
답변 (1개)
Sameer
2024년 2월 15일
Hi,
From my understanding, you're looking to retrieve data from a web service, and you've shared a JSON snippet that contains a URL under the ‘datos’ key, which seems to be the endpoint where the data can be accessed.
To retrieve data from a web service using MATLAB, you can utilize the "webread" function.
Please refer to the documentation links below:
Below is an example MATLAB code to accomplish this:
% Defined the URL from the "datos" field
datosUrl = 'https://opendata.aemet.es/opendata/sh/79adac19';
% If an API key is required, setup using weboptions
% Replace 'your_api_key_here' with the actual API key if needed
options = weboptions('HeaderFields', {'api_key', 'your_api_key_here'});
%If an API key is not required, you can simplify the options setup
%options = weboptions();
% Retrieve the data from the URL
try
% Use webread to get the data
data = webread(datosUrl, options);
% Display or process the data
disp(data);
catch ME
% Handle any errors that may occur
fprintf('Error retrieving data: %s\n', ME.message);
end
I hope this helps!
Sameer
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Web Services에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!