Embed current date into URL (matlab)

9 次查看(过去 30 天)
Yoni Verhaegen
Yoni Verhaegen 2019-6-3
移动Walter Roberson 2024-11-12,3:53
How can I embded the current date, run time and forecast hour in the URL after predefining them? I have tried the following but it doesn't work:
myrun = 00; % 00 06 12 18
mydate = 20190603; % yearmonthday
myforecasthour = 039; % t + number of hours ahead
fullURL=['https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?file=gfs.t',num2str(myrun,'%02.f'),'z.pgrb2.0p25.f',num2str(myforecasthour,'%03.f'),'&lev_surface=on&var_CAPE=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Fgfs.',num2str(mydate)'];
filename = 'cape_test';
urlwrite(fullURL,filename);
  1 个评论
Walter Roberson
Walter Roberson 2024-11-12,3:52
移动:Walter Roberson 2024-11-12,3:52
The above code, as-posted, fails with "Dimensions of arrays being concatenated are not consistent.". That is because you have
fullURL=[STUFF,num2str(mydate)']
The trailing ' transposes the num2str() result, generating a column vector. You do not want that trailing ' there.

请先登录,再进行评论。

回答(1 个)

Udit06
Udit06 2024-11-12,3:18
移动:Walter Roberson 2024-11-12,3:53
Hi Yoni,
If I run the code that you have given, I am getting the error as shown below:
myrun = 00; % 00 06 12 18
mydate = 20190603; % yearmonthday
myforecasthour = 039; % t + number of hours ahead
fullURL=['https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?file=gfs.t',num2str(myrun,'%02.f'),'z.pgrb2.0p25.f',num2str(myforecasthour,'%03.f'),'&lev_surface=on&var_CAPE=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Fgfs.',num2str(mydate)'];
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Since the variables myrun, mydate, myforecasthour are of integer type. You can replace %f with %d which will also allow you to add leading zeros.
fullURL = ['https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?', ...
'file=gfs.t', num2str(myrun, '%02d'), 'z.pgrb2.0p25.f', num2str(myforecasthour, '%03d'), ...
'&lev_surface=on&var_CAPE=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Fgfs.', num2str(mydate)]
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by