Reagrding reading file name

1 次查看(过去 30 天)
Uday
Uday 2011-8-23
I have some text data file which is from 1970:5:2000 the file name is v_CH_1970_II_1A.txt,
v_CH_1975_II_1A.txt,
v_CH_1980_II_1A.txt.....till 2000.
in the same folder I have some other data which has file name v_CH_1970_II_1A.txt
v_CH_1970_II_1A2.txt
v_CH_1970_II_1A3b.txt
v_CH_1970_II_1A6a.txt ---- ( different 13 files)
v_CH_1975_II_1A.txt
v_CH_1975_II_1A2.txt
v_CH_1975_II_1A3b.txt
v_CH_1975_II_1A6a.txt ---- ( diffrent 13 files)
So I would like to read all major years from 1970:5:2000 same time I want to read data from other 13 different files for individual year e.g for 1970
v_CH_1970_II_1A.txt
v_CH_1970_II_1A2.txt
v_CH_1970_II_1A3b.txt
v_CH_1970_II_1A6a.txt
---- ( diffrent 13 files)
somebody please tell me how I can set for loop so I can read both data sets same time?

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-8-23
for k=1970:5:2000
FileStr=sprintf('v_CH_%d_II_1A*.txt');
Files=dir(FileStr);
for j=1:length(Files)
data=textread(Files(j).name);
end
end
  2 个评论
Uday
Uday 2011-8-24
there are some files in different files
v_CH_1970_II_1A_Exe.txt
v_CH_1970_II_6b.txt
v_CH_1970_II_1b.txt
v_CH_1970_II_7.txt
So the structure of name is not constant , so how I can read in this condition
Fangjun Jiang
Fangjun Jiang 2011-8-24
Change this line
FileStr=sprintf('v_CH_%d_II_*.txt');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by