フィルターのクリア

Changing header in a set of files from the directory

1 回表示 (過去 30 日間)
Gokul  Kanneganti
Gokul Kanneganti 2016 年 8 月 14 日
コメント済み: Azzi Abdelmalek 2016 年 8 月 15 日
Hi Matlab Users,
I have a folder containing more than 10,000 text files (each file dimension is 12997rows x 1column). I wanted to remove the first row of all the files and insert a three row header (Text, 1/1/1979, 12/31/2014) in all the files. Can anyone help me in this regard.
Thanks in Advance.
Regards, Gokul

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 14 日
編集済み: Azzi Abdelmalek 2016 年 8 月 15 日
EDIT
f='C:\Users\mal\Documents\MATLAB' % your folder containing your text files
fi=dir(fullfile(f,'*.txt'))
file={fi.name}
text={'Text'; '1/1/1979',; '12/31/2014}'}
for ii=1:numel(file)
fic=fullfile(f,file{ii})
fid=fopen(fic)
s=textscan(fid,'%s','headerlines',1,'delimiter','\n')
fclose(fid)
out=[text;s{:}]
fid=fopen(fic,'w')
for k=1:numel(out)
fprintf(fid,'%s\r\n',out{k})
end
fclose(fid)
  4 件のコメント
Gokul  Kanneganti
Gokul Kanneganti 2016 年 8 月 15 日
In the first "for" loop "k" is not defined. So, the code is not running.
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 15 日
You are right, it's ii not k. Look at the edited answer

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by