writematrix: missing "newline" option...
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 4 de Mayo de 2022
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 comentarios
Rik
el 4 de Mayo de 2022
If you really have to, you can also read the resulting file and replace the line endings with the kind you need.
Walter Roberson
el 4 de Mayo de 2022
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.
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!