フィルターのクリア

Process a sequence of files

5 ビュー (過去 30 日間)
Emmanuelle
Emmanuelle 2012 年 10 月 29 日
EDIT2
I have a question about how can I process a sequence of files. What I've done is extract some information of one file (49271) to write it on a new one ('text'). The problem is I don't know how to do it with a sequence of txt files and also, how can write it on 'text.txt' the result 'line by line'.
myPath = 'C:\EX\';
a= dir (fullfile(myPath,'*.DIM'));
fileNames = { a.name };
for k = 1:length(fileNames)
newFileName = [fileNames{k}(1:2) fileNames{k}(4:6) '.txt'];
movefile([myPath fileNames{k}], [myPath newFileName]); % rename the files
end
`% extract information
fid = fopen('49271.txt', 'r');
for i = 1:18
m = fgetl(fid);
end
result2 = m([12:19]);
fid = fopen('49271.txt', 'r');
for i = 1:30
p = fgetl(fid);
end
result3 = p([12:19]);
fid = fopen('49271.txt', 'r');
for i = 1:31
q = fgetl(fid);
end
result4 = q([12:20]);
fid = fopen('49271.txt', 'r');
for i = 1:19
r = fgetl(fid);
end
result5 = r([12:20]);
% copy information in a new variable (of one line)
load('text.txt');
text= {newFileName, result2, result3, result4, result5}
I'm trying with the following code but I don't know how to write it:
filePattern=fullfile( myPath,'*.txt');
txtFiles= dir(filePattern);
for k = 1:length(txtFiles)
baseFileName=txtFiles(k).name;
fullFileName= fullfile(myPath,baseFileName);
fid=fopen('filePattern', 'r');
for i = 1:18
m = fgetl(fid);
end
result2 = m([12:19]);
end
Thanks in advance!

採用された回答

Pedro Villena
Pedro Villena 2012 年 10 月 30 日
filePattern=fullfile( myPath,'*.txt');
txtFiles= dir(filePattern);
for k = 1:length(txtFiles.names),
fullFileName=fullfile(myPath,txtFiles(k).name);
fid=fopen(fullFileName, 'r');
for i = 1:18
m{i} = fgetl(fid);
end
result2 = m{12:18};
end
  1 件のコメント
Emmanuelle
Emmanuelle 2012 年 10 月 31 日
You're a crack! Thanks so much Pedro, it works! ;)

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 10 月 30 日
It is tricky to skip characters in text files without reading them. It is much easier to read the text and throw away what you do not want.
  1 件のコメント
Emmanuelle
Emmanuelle 2012 年 10 月 30 日
Hi Walter! Yes, you were right. I've changed the way to do it and I've edited the question again.

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by