Problem 43671. Words Count: A Cell Array Approach
Given an input character vector consisting of words, punctuation marks, white spaces, and possibly newline characters (\n), arrange the unique words alphabetically in a cell array of character vectors (formerly called cell array of strings) and calculate the histogram count of every unique word.
Assumptions:
- Case is insensitive, e.g., WORDS and words are treated as the same word, and you may return in the output cell array either the uppercase or lowercase.
- Punctuation marks are limited only to comma (,), period (.), colon (:), semi-colon (;), question mark (?), and exclamation mark (!).
For example, given the input txt as a character vector,
txt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';
the outputs should be
words = {'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';...
'on';'problems';'trivial'};
count = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];
Hint: The cell array of strings approach is the dual of the string array approach, i.e., things that can be done via the string arrays approach can also be done using the cell array approach.
Related problems in this series:
- Words Count: A String Array Approach
- Words Count: A Cell Array Approach
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers62
Suggested Problems
-
22454 Solvers
-
Find the alphabetic word product
3434 Solvers
-
Find the maximum number of decimal places in a set of numbers
3256 Solvers
-
520 Solvers
-
Count consecutive 0's in between values of 1
489 Solvers
More from this Author28
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!