问题
I am using the function dlmcell in Matlab to output text. I want text on a new line each time I append using dlmcell.
When I open my written document in Notepad++, each snippet of text is on a new line as I want it. However, opening it in Notepad that comes with windows, everything is on the same line. Can somebody tell me why this is, and how to fix it?
回答1:
I'm assuming you're using the string \n
to declare a new line in your output. For Notepad++ this is sufficient, because it interprets a new line just with \n
. For the Windows Editor you need to include the carriage return also:
substitute:
\n
with \r\n
This way not just a new line is created, it also tells the editor to actually continue on the next line.
To illustrate what I mean, open your output file with Notepad++ and activate View > Show Symbol > All characters and you will see something like:
I wrote this with Notepad++ and it automatically adds CR (carriage return) and LF (line feed) at the end of every line. Matlab doesn't if you don't tell it. So your output file only contains LF without the above mentioned substitution.
I've had a look into dlmcell
, which is a FEX-function. In the current version \r\n
is implemented actually. Do you have the newest version of that function (Download)? If not, something else must be wrong, please post some code.
来源:https://stackoverflow.com/questions/25999664/line-breaks-using-dlmcell-in-matlab-shows-up-in-notepad-but-not-notepad