use regexp to find specific names.

4 次查看(过去 30 天)
FaryTak
FaryTak 2016-12-31
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

回答(1 个)

mizuki
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 个评论
per isakson
per isakson 2016-12-31
How do you know the name of the day?
FaryTak
FaryTak 2016-12-31
I know there is one file for each day. I can find them by YYYYMMDD going through each day of a year. But the rest of the name starts with "DPR" and ends with ".dat". the other parts of the file's names are unknown.

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by