writematrix: missing "newline" option...
조회 수: 22 (최근 30일)
이전 댓글 표시
I have some script exporting data into textfile using "dlmwrite", but Matlab HelpCenter says "dlmwrite is not recommended, use writematrix instead". So I would like to convert my script, but how can I control line terminator with "writematrix"? I'm using "newline" option with "dlmwrite" frequently, because I have to move data between windows/linux...
댓글 수: 0
답변 (1개)
Walter Roberson
2022년 5월 4일
writematrix() does not support any ways to configure the end of line.
However, if the issue issue is windows vs linux, then you should not worry about it, as the ways to read text almost all ignore carriage returns. load() and readmatrix() ignore carriage returns for example.
There are some commands that do not ignore carriage returns. If you fopen() a file then you can include the 't' access right, such as fopen(filename, 'rt') to make it explicit that you want carriage returns to be ignored.
댓글 수: 2
Rik
2022년 5월 4일
If you really have to, you can also read the resulting file and replace the line endings with the kind you need.
Walter Roberson
2022년 5월 4일
S = fileread(NameOfCSV);
oldlen = length(S);
S(S == newline) = [];
if length(S) ~= oldlen
fid = fopen(NameOfCSV, 'w');
fwrite(fid, S);
fclose(fid);
end
The code might possibly have to change a little if the matrix contains unicode characters.
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!