Problem 44853. Mean number of letters per word (Hard)
The previous problem in this series is 44852.
Given a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.
You may make the following assumptions:
1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.
2. There may be redundant spaces in the sentence.
3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.
4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.
Example:
c = 'The quick brown fox jumps over the lazy dog';
a = 3.889; g = 3.792
Example:
c = 'Another one bites the dust';
a = 4.400; g = 4.169
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
2240 Solvers
-
222 Solvers
-
Find matching string from a list of strings
253 Solvers
-
282 Solvers
-
Return the first and last characters of a character array
9806 Solvers
More from this Author45
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!