Why does the "-ASCII" option flag with the SAVE function add extra end-of-line characters in MATLAB?

4 views (last 30 days)
Why does the "-ASCII" option flag with the SAVE function add extra end-of-line characters in MATLAB?
When I create or load data into MATLAB and then write it out to a file using the SAVE function with the -ascii option flag, it adds extra characters to the end of each row of data. This behavior did not happen in versions of MATLAB previous to MATLAB 6.1 (R12.1).
The code below replicates this behavior:
% First create some data
h = rand(15,2);
% Now save h in ASCII format to a .dat file
save newoutput.dat h -ascii
Now open newoutput.dat in Notepad. You will notice that at the end of each row of data, an extra character has been appended. This extra control character has the appearance of having been generated in UNIX.
Note, however, that the output looks correct if you open it within Wordpad.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed for Release 14 (R14). For previous releases, please read below for any possible workarounds:
This issue has been forwarded to our development staff for further investigation.
You can try either of the two following workarounds:
1. Send your newoutput.dat file to a UNIX machine by binary mode using FTP and then import it back to the PC in ASCII mode.
2. Consider using the low-level file I/O routine FPRINTF.
For example:
fid = fopen('newoutput.dat', 'wt');
fprintf(fid, '%f %f\n', h);
fclose(fid);
3. Consider using the tr command in DOS for translating or deleting characters in a file.
Type the following in a DOS window for more information.:
tr ?

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!