Individual files reading

조회 수: 3 (최근 30일)
Uday
Uday 2011년 8월 18일
I have some daily data , files shows the details of year, month and day GSAT20090101_xyz.h5, GSAT20090102_xyz.h5 ...31 , same for month 02 also.
I wanted to read only one month file from this folder e.g jan 1-31, 1-28 ...
I am new in matlab, so somebody please tell how i can set for loop for this problem.

채택된 답변

Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 8월 18일
On a quick thought, it would be something like this:
files = dir('*.h5'); % Find the files with extension .h5 in the current directory.
month = '01'; % Month must be a string ('01' for January, '02' for February, etc.).
for ii = 1:numel(files)
nameFound = strfind(files(ii).name, ['GSAT2009' month]);
if nameFound
fid = fopen(files(ii).name);
% Do whatever you need with the files here.
fclose(fid);
end
end
EDIT
If you want to read year information separately, you can use the following, which is very similar:
files = dir('*.h5'); % Find the files with extension .h5 in the current directory.
month = '01'; % Month must be a string ('01' for January, '02' for February, etc.).
year = '2009'; % Year must be a string.
NOTE: If month or year are not strings and are numeric (double), you can use the function num2str.
for ii = 1:numel(files)
nameFound = strfind(files(ii).name, ['GSAT' year month]);
if nameFound
fid = fopen(files(ii).name);
% Do whatever you need with the files here.
fclose(fid);
end
end
Try it and let me know if it works.
  댓글 수: 3
Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 8월 18일
See the edit please ;)
Uday
Uday 2011년 8월 19일
This codes works for only one month, like month='1'but if I want to read data for all month than that string does not work. (month-'1''2'...; )
could you please tell me how I can fix this issue ?
I would like to read all days files those are available for that particular month and it should select next month (e.g jan 1-31 the it should go to feb 1-28 , march ....)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by