dawnoflife
dawnoflife

Reputation: 1652

Printing data to text file

I am using the fprintf command to store the contents of a .mat file to a .txt. The .mat file contains strings. My code prints the data in the same column.

fid = fopen('exp.txt','wt');
for i=1:275
    fprintf (fid,classes{i}{1})
end
fclose(fid);

When I use the \n and the '\r\n' options, they doesn't print anything to the file. I'd appreciate the help!

Upvotes: 0

Views: 989

Answers (1)

Shaunak
Shaunak

Reputation: 18008

Some text editors will show those new line characters and some wont. This happens because of different standards followed by different softwares and operating systems for eg:

end of line sequences
Windows end of line sequence:  \r\n
Unix end of line sequence: \n
Mac end of line sequence: \r

So if you really want good human readable formats, either fix your operation system/software and use characters friendly for that system, or if you want uniformity in the reports, better write files in standard HTML formats :) adding a "br" tag and naming file .html is as simple as writing out '\n' and naming it .txt!

Upvotes: 1

Related Questions