How to delete the first line of a text file?
4 ビュー (過去 30 日間)
古いコメントを表示
I'd like to import a text file, delete the first line, and save the remaining lines to a new text file. The first line consists of a single number, while the remaining lines have the same number of elements in each of them. For instance, one of these input text files might look like this:
20
1 2 3 4
5 6 7 8
9 0 1 2
What I'd like to do is take the above text file and create a new text file that looks like this.
1 2 3 4
5 6 7 8
9 0 1 2
I'd also like to name the new text file something that includes the value in the first line (e.g, "filename20.txt"). Help?
0 件のコメント
採用された回答
oblivious
2012 年 6 月 5 日
I could not put the file name as you wanted. but i did the rest of the things
clear all;
fclose('all')
fid=fopen('oldfile.m','rt');
fid2=fopen('newfile.m','wt');
id=0;
a=fgets(fid);
while(ischar(a))
id=id+1;
if id==1
a=fgets(fid);
continue
else
fprintf(fid2,a);
end
a=fgets(fid);
end
newfile.m will have your desired output
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!