analyse txt file with rows of different length
Show older comments
Hello, I have a data file input.txt which looks like this (simplified)
hello world
the sun
i like the sun
sun world world
what I want is to read this file, count the distinct words and make a matrix of it, which has the form
word1 word2 word3 ... wordn
example1 * * * ... *
example2 * * * ... *
...
examplem * * * ... *
where the * represents how many times a word is in that specific example. In this case the matrix will look like this:
1 1 0 0 0 0
0 0 1 1 0 0
0 0 1 1 1 1
0 2 0 1 0 0
I have tried this with textscan, but I get stuck with the cell arrays. I hope someone can help me with this..
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Export in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!