retrieving solar irradiance data through webread function
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
how can i retrieve solar irradiance data of 24 hours from https://www.newquayweather.com/pwsWD/index.php in MATLAB through webread function?
채택된 답변
This is a way to get it instantaneously.
url = 'https://www.newquayweather.com/pwsWD/index.php';
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
Here's a way to run it over an entire 24 hours.
clear
url = 'https://www.newquayweather.com/pwsWD/index.php';
SecBetweenReading = 10; %seconds between each reading
for x = 1:3600*24/SecBetweenReading %3600 seconds in an hour, 24 hours
w = webread(url); %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
pause(SecBetweenReading) %pause for a given amount of time
end
plot(dt,tsi,'-o') %plot at the end
thanks cameron for the guidance, is there any other way to visualize solar irradiance data for 24 hours. i run the above code and it gives me 10-Mar-2023 18:08:25
10-Mar-2023 18:08:37
10-Mar-2023 18:08:48
10-Mar-2023 18:09:00
10-Mar-2023 18:09:12
10-Mar-2023 18:09:23
10-Mar-2023 18:09:35
10-Mar-2023 18:09:47
in command window. i want to visualize it also.
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.
clear
url = 'https://www.newquayweather.com/pwsWD/index.php'; %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
fprintf(fileID,'%s,%d\n',dt(x,1),tsi(x,1));
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
end
pause(SecBetweenReading) %pause for a given amount of time
end
fclose(fileID);
If you're having difficulties deleting files, you may have not used the fclose() function on one of your .txt files. I would use
fclose('all')
if you're getting an error from your computer saying MATLAB has a certain file open.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
