Extracting Data and Text from a file

9 visualizaciones (últimos 30 días)
Adam
Adam el 28 de Ag. de 2023
Respondida: Adam el 28 de Ag. de 2023
I am currently trying to extract the following data out of a txt file.
type sample.txt
9640 12783 she 12783 17103 had 17103 18760 your
into a column vector using the following code
audioWord = fopen("sample.txt","r");
formatSpec = "%i %i %s";
A = fscanf(audioWord,formatSpec,[3 Inf])
A = 3×6
9640 104 17103 100 121 114 12783 101 104 17103 111 0 115 12783 97 18760 117 0
But it only partially works for the first data point, with the rest of the data not correctly parsed.

Respuesta aceptada

Adam
Adam el 28 de Ag. de 2023
I have managed to find the readtable function which seems to work.
A = readtable("sample.txt")
A = 3×3 table
Var1 Var2 Var3 _____ _____ ________ 9640 12783 {'she' } 12783 17103 {'had' } 17103 18760 {'your'}

Más respuestas (0)

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by