Borrar filtros
Borrar filtros

organize the inside of the .txt file

2 visualizaciones (últimos 30 días)
Alberto Acri
Alberto Acri el 17 de Jun. de 2023
Comentada: Star Strider el 18 de Jun. de 2023
How can I organize the data.txt file to get the data_new.txt file?

Respuesta aceptada

Star Strider
Star Strider el 17 de Jun. de 2023
Editada: Star Strider el 17 de Jun. de 2023
Define the delimiter in your writetable call to be the tab '\t' character —
type('data.txt')
data 1,data 2,data 3 50,140,36
type('data_new.txt')
data 1 data 2 data 3 50 140 36
T1 = readtable('data.txt', 'VariableNamingRule','preserve')
T1 = 1×3 table
data 1 data 2 data 3 ______ ______ ______ 50 140 36
writetable(T1, 'new_file.txt', 'Delimiter','\t') % Write New File
type('new_file.txt')
data 1 data 2 data 3 50 140 36
I am not certain that it is possible to change the delimiter from a comma (,) to a tab except by writiing it to a new file.
EDIT — Corrected typographical errors.
.
  4 comentarios
Alberto Acri
Alberto Acri el 18 de Jun. de 2023
Thank you for your reply. The table that is generated in the matlab workspace is fine. I should save the .txt as that table. Currently, the inside of the new .txt file (saved with writetable) does not match the table created on the workspace.
type('data_1.txt');
T1 = readtable('data_1.txt', 'VariableNamingRule','preserve');
writetable(T1, 'data_new.txt', 'Delimiter','\t');
Star Strider
Star Strider el 18 de Jun. de 2023
What the file contains internally is irrelevant. It only has to produce the correct result when read.
If you want it to look like that internally, use the Contact Support link to submit an enhancement request. Include the URL of this thread in your note to MathWorks.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by