Hello,
I have a text file that is in the following form:
"1981-02-01",15.3
"1981-02-02",18.8
"1981-02-03",21.9
"1981-02-04",19.9
I want to edit these two line and make it like as shown below:
1 15.3
2 18.8
3 21.9
4 19.9
I am looking for a MATLAB function that does this automatically without having to change my file manually because the original file contains 500 lines.
thank you

 Respuesta aceptada

Star Strider
Star Strider el 14 de Dic. de 2020
Try this:
textfile = {"1981-02-01",15.3
"1981-02-02",18.8
"1981-02-03",21.9
"1981-02-04",19.9};
T1 = cell2table(textfile);
T1.textfile1 = datetime(T1.textfile1, 'InputFormat',"yyyy-MM-dd");
T2 = [day(T1.textfile1) T1.textfile2]
producing:
T2 =
1 15.3
2 18.8
3 21.9
4 19.9
For your text file, use readtable to import it as a table. I use cell2table here for obvious reasons.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Dic. de 2020

Respondida:

el 14 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by