"thou"
Collect Basic Statistics in Table
Calculate the total number of occurrences of each word in sonnetWords. Calculate the
number of occurrences as a percentage of the total number of words, and calculate the
cumulative percentage from most to least common. Write the words and the basic
statistics for them to a table.
numOccurrences = numOccurrences(rankIndex);
numOccurrences = numOccurrences';
numWords = length(sonnetWords);
T = table;
T.Words = wordsByFrequency;
T.NumOccurrences = numOccurrences;
T.PercentOfText = numOccurrences / numWords 100.0;
T.CumulativePercentOfText = cumsum(numOccurrences) / numWords 100.0;
Display the statistics for the ten most common words.
T(1:10,:)
ans=10×4 table
Words NumOccurrences PercentOfText CumulativePercentOfText
"and" 490 2.7666 2.7666
"the" 436 2.4617 5.2284
"to" 409 2.3093 7.5377
"my" 371 2.0947 9.6324
"of" 370 2.0891 11.722
"i" 341 1.9254 13.647
"in" 321 1.8124 15.459
"that" 320 1.8068 17.266
"thy" 280 1.5809 18.847
"thou" 233 1.3156 20.163
Analyze Text Data with String Arrays