MATLAB: How to delete the first 2 rows (Headers) of a txt file

commanddeletefileheadertxt

Hello,
How to delete the first two rows , which are Headers , in a .txt file? I use these command to read it
file=regexp(fileread('data.txt'), '\r?\n', 'split') .';

Best Answer

Well, once you've got the right content in memory, then just rewrite the file. But, specifically on that has some bearing on the content for easy ways.
But, if that is the only thing you care to do, then the simplest irrespective of what the file content is, is probably
fidi=fopen('oldfile.txt','r');
fido=fopen('newfile.txt','w');
headerlines=2;
for i=1:headerlines,fgetl(fidi);end % skip the desired number
buf=fread(fidi,'*char'); % suck up the rest as image
fwrite(fido,buf) % and spit it out verbatim
fclose('all') % done
%delete('oldfile.txt') % optionally remove the original keeping new
%movefile('newfile.txt','oldfile.txt') % optionally rename new to old (only new left as oldfile name)