MATLAB: Read multiple txt files and remove 2nd line with all dashes and output back to files to append _output in the filenames

I have multiple .txt files to read and want to remove the 2nd line with all dashes in all files. Then each of them should be saved with the same filename. Or appended with "_output.txt".
I Have the following codes, but it only generate files without contents. Can someone helps?
SBFsample=dir('/Users/ichen/Documents/MATLAB/SBF/*.TXT'); % Identify a directory and TXT files to be merged/processed
for i=1:length(SBFsample)
fid=fopen(SBFsample(i).name,'r'); % Open each data file in turn
fidOut=fopen(SBFsample(i).name,'output.txt','w'); % Open an output file
hdr = textscan(fid,'%s',1,'Delimiter','\n','Whitespace',''); % Capture the header line
fprintf(fidOut,'%s\n',hdr{1}{:}); % Print header file and
for i=1:1, fgetl(fid); end % Skip and remove the dash line remove the dash line on the original data file
fwrite(fidOut,fread(fid,'*char'),'*char') % Read remainder as char* image and echo back out
fclose(fidOut);
fclose(fid); % Complete reading and combining individual file ...
end % Close the output file

Best Answer

I run your code successfully after having replaced
fidOut=fopen(SBFsample(i).name,'output.txt','w');
by
fidOut=fopen( [SBFsample(ii).name,'_output.txt'],'w');
The code requires that the text files are in the current directory