Problem 1757. Letter and word frequency

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.

Solution Stats

53.57% Correct | 46.43% Incorrect
Last solution submitted on Aug 07, 2016


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

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!