matlab读取网络数据的能力和python相比太弱了,python有很多开源工具包,功能非常强大。其实以前批量下载数据都是用python语言写的,但是现在因为工作需要每天都要用matlab,所以尝试用matlab写个小程序批量下载网络数据。要下载的数据网址是:
http://www.esrl.noaa.gov/psd/thredds/catalog/Datasets/godas/catalog.html
要下载的数据如下:pottmp.1980.nc到pottmp.2016.nc,共37个nc文件
程序如下,核心函数是urlwrite
filepath='D:\用户目录\Desktop\pottmp\'; mkdir(filepath); %在桌面创建文件夹pottmp
for i=1980:2016 fullURL=['http://www.esrl.noaa.gov/psd/thredds/fileServer/Datasets/godas/pottmp.',num2str(i),'.nc'];%下载网址 filename=[filepath,'pottmp.',num2str(i),'.nc']; %保存的文件名 tic; [f,status]=urlwrite(fullURL,filename);%下载命令 if status==1 t=toc; lst=dir(filename); xi=lst.bytes; disp(['pottmp.',num2str(i),'.nc','下载成功','文件大小为',num2str(xi/1024/1024),'M',' 花费',num2str(t/60),'分钟']); else disp(['pottmp.',num2str(i),'.nc','下载失败']); end end
这里下载的网址是非常容易就能看到的,有的网站需要借助F12开发者工具才能得到下载的网址