Dynamic Input File Name Recognition
이전 댓글 표시
Hello, I have many binary (*.grb) files to evaluate them in a function, but I want to call multiple (precisely 4) input files into the function from a directory. Files contain satellite data taken every 15 min period for the selected day. Here is an example name of an input binary file;
MSG2-SEVI-MSGMPEG-0100-0100-20100706130000.000000000Z-999896.grb
"MSG2-SEVI-MSGMPEG-0100-0100-"Part is same for all binaries;
Next "20100706" part is the date 07/06/2007 - Variable;
Next "13" is the hour of the day - Variable (from 00 to 23);
Next "00" is the minute of the hour of the day - Variable (00, 15, 30, 45);
Next "00" is second, and zero for all files ;
Next ".000000000Z-" part is again same for all files;
Next "999896" part is NOT same, but it has no use in functions;
Lastly ".grb" is the file extension as I expressed above.
What I want to do is to call all 15 minute period data (00,15,30,15) for a specific hour, in this case for the hour 13:00, and run them in the function. To do this I wrote the following wrong and insufficient code to call the files.
function MPEH(yr,mon,day,hr)
....
....
....
....
for i=1:4
min=['00';'15';'30';'45'];
In= strcat('MSG2-SEVI-MSGMPEG-0100-0100-20',yr,mon,day,hr,min(i),'00.000000000Z- and some code needed to ignore the rest');
Filename=strcat(In,'*.grb');
.....
.....
.....
What I need is to make Matlab ignore the same parts in the beginning and also the variable but not important part of the file names. As a summary recall of an example, When I type the following;
MPEH(10,07,06,13)
I need Matlab recognize and load the following files;
MSG2-SEVI-MSGMPEG-0100-0100- 201007061300 00.000000000Z-999896.grb
MSG2-SEVI-MSGMPEG-0100-0100- 201007061315 00.000000000Z-1010592.grb
MSG2-SEVI-MSGMPEG-0100-0100- 201007061330 00.000000000Z-999896.grb
MSG2-SEVI-MSGMPEG-0100-0100- 201007061345 00.000000000Z-1010592.grb
I know I failed to express my problem, Sorry for it, but I couldn't find a better way to describe it.
Many many thanks in advance.
채택된 답변
추가 답변 (2개)
Nirmal Gunaseelan
2011년 9월 19일
0 개 추천
I'd strongly recommend using Regular Expressions for such parsing problems. It is fairly straight forward once you follow the examples in the doc page above.
Walter Roberson
2011년 9월 19일
0 개 추천
A) Please do not name a variable "min", as that conflicts with the often-used routine min()
B) The place you involve min(i) should be min(i,:) if you are going to use character arrays of rows. I would probably use cell arrays instead, keymins = {'00', '15', '30', '45'} and then keymins{i} would be the string for a particular key minute representation.
카테고리
도움말 센터 및 File Exchange에서 Text Analytics Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!