use regexp to find specific names.
4 次查看(过去 30 天)
显示 更早的评论
Hi
I've been trying to download some specific files from the web with name
'DPR-NS-12755-V04A.MRMS-XXXXXXXX.114200.matched-130W_55W_20N_55N.extract.dat'
The XXXXXXXX is the yyyymmdd that changes with the loop. I used regexp. But it returns just XXXXXXXX and not the entire name. I used something ugly (which worked finally) to download my file as:
expr = [sprintf('%02.0f', y), sprintf('%02.0f', m), sprintf('%02.0f', d)];
% y = year, m = month, d is day
a = regexp(str,expr);
filename=str(a-22:a+51);
I know it is very armature to use something like this!. Can you help me to parcel the name of these files in a more professional way? I read the regexp doc in Matlab but it is a little confusing for me.
Thanks,
Zeinab
0 个评论
回答(1 个)
mizuki
2016-12-31
Use datetime instead of regular expressions:
% from 2016/12/01 to 2016/12/10 with every other day
datevec = datetime(2016,12,01):day(2):datetime(2016,12,10);
t = datestr(datevec, 'yyyymmdd');
for i = 1:size(t,1)
filename = ['DPR-NS-12755-V04A.MRMS-', t(i,:), '114200.matched-130W_55W_20N_55N.extract.dat'];
% webread(filename)
end
3 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!