file write problem

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

The made a below script.

When I see the read3.txt file it has different show.

 

['notepad program']

It doesn't have a line change.

image.png.9f76f7185a7af589a1d331d950e12534.png

 

['notepad++ program']

It has a line change

image.png.4b60b7ddadc38fa01f7da81b55963541.png

 

 

How can I make a read3.txt file to be read same as 'notepad++ program'   at 'notepad program'.

 

 

file = 'read3.txt';
fid = fopen(file, 'w');
AA=[1,2;3,4;5,6];


for i=1:3
fprintf(fid,'%f %f \n', AA(i,:)); 
end


fclose(fid);

 

 

 

Tagged:

Answers

  • Matthieu Pupat
    Matthieu Pupat
    Altair Employee
    edited June 2018

    This is because Notepad can only properly display files with Windows newline (CR+LF).

    The code you use produces UNIX newline (LF only).

     

    In Notepad++, you can control which end-of-line is used in your file by going to Edit > EOL Conversion. The greyed entry is your current end-of-line.

     

    To make Compose write a Windows EOL, that will be displayed as you expect in Notepad, please use the following code:

     

    file = 'read3.txt';
    fid = fopen(file, 'w');
    AA=[1,2;3,4;5,6];


    for i=1:3
    fprintf(fid,'%f %f \r\n', AA(i,:));
    end


    fclose(fid);

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited July 2018

    Thank you Matthieu Pupat.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.