MATLAB Answers

Translated by

이 페이지의 내용은 영어에서 자동 번역되었습니다. 자동 번역 기능을 해제하려면 "<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">여기</a>"를 클릭하십시오.


Downloading weather files from a server

Asked by alexander on 8 Jan 2012
Latest activity Edited by Cedric Wannaz
on 9 Aug 2015
I am working on a project where i need to periodically download weather forecasts from a server. I have been experimenting with the urlread() and urlwrite() functions which is easy enough. The problem is that the url for the file includes date and time of submission. So i would like to download the most recent files.
where the date and time portion changes. How can i specify a url such that i will get the most recent copy?


Sign in to comment.

1 Answers

Answer by Walter Roberson
on 8 Jan 2012
 Accepted Answer

If you urlread() on then you could pick out the most recent file.


ok i have that done. It's kind of dirty but it works. I did this:
clear all
%for most recent file use last index in relev_files
Now i want to format this data into a matrix.
i was going use character location relative to the comma and then use num2str() but this does not work on the right side of the comma. How can i specify the end of a line?
I tried (ta_data(6:\n) but this does not work.
I have worked on this and put the data in the separate matrices
close all, clear all, clc
%%download weather forecast data from server
%for most recent file use last index in relev_files
% ta_url=['',current_files(relev_files(1:end)-21:relev_files(1:end)+20)];
%%put forecast data into vectors
C = [strsplit(ta_data, '\n')]' ;
D = char(C(2:end-1));
for I = 1:length(D)
E = strsplit(D(I,:), '-');
year(I) = str2num(char(E(1,1)));
month(I) = str2num(char(E(1,2)));
F = char(E(1,3));
G = strsplit(F, 'T');
day(I) = str2num(char(G(1,1)));
H = char(G(1,2));
J = strsplit(H, ':');
hour(I) = str2num(char(J(1,1)));
min(I) = str2num(char(J(1,2)));
K = char(J(1,3));
L = strsplit(K, 'Z');
sec(I) = str2num(char(L(1,1)));
M = char(L(1,2));
N = strsplit(M, ',');
value(I) = str2num(char(N(1,2)));
% F = strsplit(D(1,:), 'T')
[year' month' day' hour' min' sec' value']
t = datetime(year, month, day, hour, min, sec);
plot(t, value, '*')
hold on
plot(t, value, '-k', 'Linewidth', 2)
axis tight, grid minor
ylabel('Temperature (°C)')

Sign in to comment.

Translated by