Extracting Data and Text from a file

15 vues (au cours des 30 derniers jours)
Adam
Adam le 28 Août 2023
Réponse apportée : Adam le 28 Août 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.

Réponse acceptée

Adam
Adam le 28 Août 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'}

Plus de réponses (0)

Catégories

En savoir plus sur Text Data Preparation dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by