MATLAB Answers

How to download multiple data files at once using matlab

21 views (last 30 days)
I need to call on a website and download data for each and every day for the month of july. Im curious what command or format can help me do this. For example this is the code to retrieve 1 day of the year.
filename='weather_data_2019_255.txt';
if isfile(filename)
fprintf('already have the file |%s|\n',filename);
else
url='http://www.weather.unh.edu/data/2019/255.txt';
outname=websave(filename,url);
fprintf('got weather data file |%s|\n',outname);
end
How can i change the filename to allow me to download filename='weather_data_2019_(182-212).txt. I'm assuming I need to create a start date and a end date and create an output filename. May someone teach me how I can do this. Thank you very much.

  0 Comments

Sign in to comment.

Accepted Answer

meghannmarie
meghannmarie on 1 Oct 2019
Try this. I also put where you could change year also.
year = 2019;
start_jd = 182;
end_jd = 212;
for jd = start_jd:end_jd
filename=['weather_data_' num2str(year) '_' num2str(jd) '.txt'];
if isfile(filename)
fprintf('already have the file |%s|\n',filename);
else
url=['http://www.weather.unh.edu/data/' num2str(year) '/' num2str(jd) '.txt'];
outname=websave(filename,url);
fprintf('got weather data file |%s|\n',outname);
end
end

  0 Comments

Sign in to comment.

More Answers (1)

Edward McLellan
Edward McLellan on 4 Oct 2019
thanks meghannmarie, that really helped lay everything out for me.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags

Products


Release

R2019a