MATLAB Write a function called analyzeText that accepts a st

MATLAB Write a function called analyzeText that accepts a string as input and (1) counts the number of words; (2) identifies the length of the longest word; and (3) 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.

Solution


function [numWords,maxWordLength,maxNumVowels] = analyzeText(text)
arr=strsplit(text)
[r,c]=size(arr)
numWords=c
maxWord=0
for i=1:c
maxVowels=0
maxNumVowels=0
str=char(arr(1,i))
if(length(str)>maxWord)
maxWord=length(str)
end
for j=1:length(str)
if(str(j)==\'a\'||str(j)==\'e\'||str(j)==\'i\'||str(j)==\'o\'||str(j)==\'u\')
maxVowels=maxVowels+1
end
end
if(maxVowels>maxNumVowels)
maxNumVowels=maxVowels
end
end
maxWordLength=maxWord
end
analyzeText(\"dsa afsdf asfasdg asfgg dfgdgdfg dghghhfgh\")

MATLAB Write a function called analyzeText that accepts a string as input and (1) counts the number of words; (2) identifies the length of the longest word; and

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site