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);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.