Extracting Data and Text from a file

22 views (last 30 days)
Adam
Adam on 28 Aug 2023
Answered: Adam on 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.

Accepted Answer

Adam
Adam on 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'}

More Answers (0)

Categories

Find more on Text Data Preparation in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!