output_filename = 'example.txt';
fid = fopen('datafile.phy', 'rt');
if (fid == -1)
error(['The file cannot be opened!'])
end
while feof(fid) == 0
line = fgetl(fid); %grab a line from the file
x = line (1 : length(line)); %remove the unwanted characters from the sequence
x = strrep(x, '-', ''); %remove dashes and replace with no spaces^
%now write the line to the example file -- output_filename
test = fopen(output_filename, 'a');
write = fwrite(test, x, 'char*1'); %write the line to the file, which is opened for
%appending. Or for fprintf I've tried:
write = fprintf(output_filename, '\n', x);
end
fclose(test);
fclose(fid);
return
The problem is my data is all on 1 very long line. Instead of the 12 lines it should be, without spaces, and without dashes. Therefore it is not APPENDING the way I would like it - it is just simply attaching 1 line to the next, and removing the spaces and dashes. Any help would be greatly appreciated.
Thanks!
-Dan
> fid = fopen('datafile.phy', 'rt');
*snip*
> %now write the line to the example file -- output_filename
> test = fopen(output_filename, 'a');
You're reading from the input file as text; so why aren't you writing to the
output file as text as well?
*snip*
--
Steve Lord
sl...@mathworks.com
If you don't put in a format, it only prints out a new line.
"Daniel " <che...@indiana.edu> wrote in message
news:gus5ji$6gt$1...@fred.mathworks.com...