Extracting Data and Text from a file

12 Ansichten (letzte 30 Tage)
Adam
Adam am 28 Aug. 2023
Beantwortet: Adam am 28 Aug. 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.

Akzeptierte Antwort

Adam
Adam am 28 Aug. 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'}

Weitere Antworten (0)

Kategorien

Mehr zu Text Data Preparation finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by