use regexp to find specific names.

5 views (last 30 days)
FaryTak
FaryTak on 31 Dec 2016
Edited: per isakson on 19 Jan 2017
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

Answers (1)

mizuki
mizuki on 31 Dec 2016
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 Comments
per isakson
per isakson on 31 Dec 2016
How do you know the name of the day?
FaryTak
FaryTak on 31 Dec 2016
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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!