Borrar filtros
Borrar filtros

retrieving solar irradiance data through webread function

3 visualizaciones (últimos 30 días)
Muhammad el 9 de Mzo. de 2023
Comentada: Muhammad el 11 de Mzo. de 2023
how can i retrieve solar irradiance data of 24 hours from in MATLAB through webread function?

Respuesta aceptada

Cameron el 9 de Mzo. de 2023
Editada: Cameron el 9 de Mzo. de 2023
This is a way to get it instantaneously.
url = '';
w = webread(url);
loc1 = strfind(w,'W/m²');
B = str2num(string(regexp(w(loc1-10:loc1),'\d*','Match')));
fprintf('Solar irradiance at %s is %d W/m²',datetime('now'),B)
Solar irradiance at 09-Mar-2023 15:18:03 is 174 W/m²
  4 comentarios
Cameron el 10 de Mzo. de 2023
There are a couple of things you can do. The reason I didn't plot the tsi vs date is because if you were to close the graph, the program would stop. You can either run the script until 1 whole day has passed or you can hit Control+C to manually stop the program. The variables for dt and tsi should be in your workspace up until you stopped the program. The code I will paste below will save your data to a .txt file you specify prior to reading data from the website. So you can open this file to see all the data that's been collected over a period of time. I did notice while I was running this script that sometimes the url said the solar irradiance was 0 W/m2 which wasn't true, but that's what was on the url so that's what was read by the program.
url = ''; %your url
[file,path,indx] = uiputfile('.txt'); %save a file as a .txt. you can change this to your preferred extension
if indx == 0; msg = 'No path selected.'; error(msg); end %user hits Cancel or closes uiputfile prompt
cd(path) %change path to the one designated in uiputfile
fileID = fopen(file,'a'); %open file and append any data
SecBetweenReading = 10; %seconds between each reading
opt = weboptions('Timeout',60); %set the web timeout to 60 seconds
fig = figure; %create figure
ax = uiaxes(fig); %create axes
for x = 1:3600*24/SecBetweenReading %3600 seconds in an hour, 24 hours divided by seconds between reading
w = webread(url,opt); %read the web page
loc1 = strfind(w,'W/m²'); %find where W/m2 is
B = str2num(string(regexp(w(loc1-10:loc1),'\d*','Match'))); %get only the number
dt(x,1) = datetime('now'); %save datetime
tsi(x,1) = B; %save your solar irradiance
disp(dt(end,1)) %display the most recent time the data was read
disp(tsi(end,1)) %display the most recent tsi the data was read
if isgraphics(ax) %if you have not closed the plot
plot(ax,dt,tsi,'-o') %plot all data
pause(SecBetweenReading) %pause for a given amount of time
If you're having difficulties deleting files, you may have not used the fclose() function on one of your .txt files. I would use
if you're getting an error from your computer saying MATLAB has a certain file open.
Muhammad el 11 de Mzo. de 2023
Thanks alot Cameron for the guidance.

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Live Scripts and Functions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by