use regexp to find specific names.

5 ビュー (過去 30 日間)
FaryTak
FaryTak 2016 年 12 月 31 日
編集済み: per isakson 2017 年 1 月 19 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by