Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a matlab function called analyzeText that accepts a string as input and co

ID: 3779845 • Letter: W

Question

Write a matlab function called analyzeText that accepts a string as input and counts the number of words; identifies the length of the longest word; and identifies the greatest number of vowels (a, e, i, o, u) in a word. The function will be called as follows: [numWords, maxWordLength, maxNumVowels] = analyzeText(text) where the variable text contains the string supplied to the function, numWords returns the number of words, maxWordLength returns the length of the longest word in the string, and maxNumVowels returns the greatest number of vowels present in any word.

Explanation / Answer

%m file

function [numWords,maxWordLength] = analyzeText(text)
space= strfind(text, ' ');

numWords=length(space)+1
max=0;
p=length(space);
for c= 1:p-1
if space(c+1)-space(c)>max
max=space(c+1)-space(c);
end
end
maxWordLength=max-1

end

%from console, text contains the string

>>analyzeText(text);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote