Discover MakerZone


Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 1757. Letter and word frequency

Created by Bruce Char

Here is a task:

You’re given a text file. Your first task is to create a variable in MATLAB which will hold the text given to you. You want to know: a. How many letters are present in this text? b. How many “e”s are present in the text? c. What percentage of the text do they correspond to? d. How many words are there in the text given to you? (Hint: Count the number of spaces.)

Write a function textCount1 that takes as a parameter a string which is the name of the text file. For example, if you wanted to do this analysis on a file named data.txt in your working directory, you would invoke textCount1('data.txt').

The result of the function should be a vector consisting of the number of e's and the number of words. Cody will supply the test file which will be the parameter for your function.


Problem Group

Solution Statistics

14 correct solutions 12 incorrect solutions
Last solution submitted on Oct 30, 2015