regarding specific files from folder

조회 수: 2 (최근 30일)
Uday
Uday 2011년 8월 19일
I have some data sets its for daily observations and I would like to read data for one month every time ( 30 files) and after that it should go to next month. can anybody tell me how to fix this problem?

채택된 답변

Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 8월 19일
Does this solution work for you? I have not tested it, let me know if it works.
files = dir('*.h5'); % Find the files with extension .h5 in the current directory.
monthsStr = {'01';'02';'03';'04';'05';'06';'07';'08';'09';'10';'11';'12'};
for ii = 1:numel(files) % In theory, you have 365 files.
for year = 2009:2010
for jj 1:numel(monthsStr)
nameFound = strfind(files(ii).name, ['GSAT' num2str(year) monthsStr{jj}]); % The mistake was here =P .
if nameFound
fid = fopen(files(ii).name);
% Do whatever you need with the files here.
fclose(fid);
end
end
end
end
  댓글 수: 2
Uday
Uday 2011년 8월 19일
Thank you answer
my codes are as follows
path=('/Net/Groups/BSY/people/upimple/temp/gosat/');
files=dir('*h5');
monthsStr={'01';'02';'03';'04';'05';'06';'07';'08';'09';'10';'11';'12'};
for ii=1:numel(files)
for year=2009:2010
for jj=1:numel(monthsStr)
nameFound=strfind(files(ii).name,['GOSATTFTS' num2str(year) monthsStr(jj)]);
if nameFound
laitude=hdf5read(strcat(path,files(ii).name),'/Data/geolocation/latitude');
longitude=double(hdf5read(strcat(path,files(ii).name),'/Data/geolocation/longitude'));
xco2=double(hdf5read(strcat(path,files(ii).name),'/Data/mixingRatio/XCO2'));
end
end
end
end
and I got error
??? Error using ==> cell.strfind at 35
If any of the input arguments are cell arrays, the first must be
a cell array of strings and the second must be a character array.
Error in ==> temp at 16
nameFound=strfind(files(ii).name,['GOSATTFTS'
num2str(year) monthsStr(jj)]);
Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 8월 19일
My mistake, you must use "{" and "}" instead of "(" and ")". I edited the answer, take a look at it ;).

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

추가 답변 (1개)

Wouter Donders
Wouter Donders 2011년 8월 19일
Surely the filenames contain some coded tags with which you could identify which files go with which month?
Have a look here.
  댓글 수: 1
Uday
Uday 2011년 8월 19일
my problem is that I wanted to read only specific files from all files e.g for whole year I have 365 files , I want to read them separately / month ( So accordingly every month contains 31,30 28or 29 files). the files names give me the year and month and day (gmat20090211_1245Stv.h5).

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by