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
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