how to count the no of words in a sentence?
Show older comments
i have read the text file sentence by sentence by using the following code. now i want to count the total no of words in each sentence.. how can i do that? i know how to read a text file word by word but it gives total no of words in the whole document and i want to calculate no of words for each sentence separately.
fid=fopen('hello.txt');
text = textread('hello.txt','%s','delimiter','.')
fclose(fid);
[r,c]=size(text)
3 Comments
shafaq innam
on 19 Jun 2013
Matt Kindig
on 19 Jun 2013
Can you clarify what your desired output actually is? Is it a count of letters per word, or a count of all of the letters used within a single sentence, or within the document.
I think you can do this fairly easily using hist(), but I admit that I am a bit confused as to what your final goal is. Can you post a sample text (maybe only a couple of short sentences), and your desired output?
shafaq innam
on 20 Jun 2013
Accepted Answer
More Answers (0)
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!