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

Matlab find vowels This is what I already have, but I can\'t iterate through a s

ID: 3800608 • Letter: M

Question

Matlab find vowels

This is what I already have, but I can't iterate through a string

prompt='Type a sentence 10 words long ';
my_sentence=input(prompt,'s');

k=0;
while k < length(my_sentence)
if Strcmp(my_sentence{k},a)==1
display('a')
k=k+1;
elseif Strcmp(my_sentence{k},'e')==1
display('e')
k=k+1;
elseif Strcmp(my_sentence{k},'i')==1
display('i')
k=k+1;
elseif Strcmp(my_sentence{k},'o')==1
display('e')
k=k+1;
elseif Strcmp(my_sentence{k},'u')==1
display('e')
k=k+1;
else
k=k+1;
end
end
  

Write a script file called find_vowels.m. Create a variable called my_sentence and allow the user to enter a sentence (minimum of 10 words) of his or her choosing via the input() command. Note that it may have some gaps/spaces. Your program is to extract the vowels within that sentence and display them when executed. Strcmp() in MATLAB allows you to compare two individual strings/characters (returns a 1 if they are the same and 0 if they are not the same). It is now a matter of looping over the individual letters of the sentence and performing decision making process such that only the vowels are outputted at the command prompt as we execute your program.

Explanation / Answer

Note : the program checks for the occurence of vowels for lowercase as well as uppercase.

prompt = ‘Type a sentence 10 words long ’;

my_sentence = input(prompt,’s’);

k = 0;

while k < length(my_sentence)

if Strcmp(my_sentence(k),’a’)

   display(‘a’)

if Strcmp(my_sentence(k),’A’)

   display(‘A’)

if Strcmp(my_sentence(k),’e’)

   display(‘e’)

if Strcmp(my_sentence(k),’E’)

   display(‘E’)

if Strcmp(my_sentence(k),’i’)

   display(‘i’)

if Strcmp(my_sentence(k),’I’)

   display(‘I’)

if Strcmp(my_sentence(k),’o’)

   display(‘o’)

if Strcmp(my_sentence(k),’O’)

   display(‘O’)

if Strcmp(my_sentence(k),’u’)

   display(‘u’)

if Strcmp(my_sentence(k),’U’)

   display(‘U’)

end % end of if

k = k + 1; %This statement has to be only once, for the next iteration of while

end %end of while