简体   繁体   中英

Set carriage return type for writematrix

I am trying to write data to a text file using writematrix .

 writematrix([ 1 2 3 4 5 6]' ,'patate.txt')

MATLAB encodes it by default as UTF-8 , and uses a Windows style return (CR LF) (example in Notepad++) :

记事本中的 CR LF

The name-value pair 'Encoding' can be passed to writematrix , but the documentation is not explicit on how to use it for the system type:

 writematrix([ 1 2 3 4 5 6]' ,'patate.txt', 'Encoding','UTF-8')

Is it possible to configure writematrix , or use another function, to have UTF-8 encoding but with Unix style returns (LF)?

I believe that I cannot change the carriage return to Unix format writematrix .

Thanks to Adriaan's comment I looked deeper into the source of writematrix . A some point, writeTextFile is called and calls fopen here:

% Open the file for writing
if strcmp(encoding,'system')
    [fid,errmsg] = fopen(file,'Wt'); % text mode: CRLF -> LF
else
    [fid,errmsg] = fopen(file,'Wt','n',encoding); % text mode: CRLF -> LF
end

The encoding parameter will be used in the else condition and fopen is called with a default parameter set to 'n' , which means 'native' or 'n' - local machine format - the default

Therefore I cannot force the carriage return style.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM