Finding vowels in a string the user inputs and printing the vowels. Here's the problem:
32 views (last 30 days)
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.
Jan on 24 Feb 2017
The question mentions all tools reuiqred for the solution already:
So start with obtaining the input. Then create a loop over the characters. A for loop will solve this and you might need the command length() to determine the number of characters. Then compare each character with the vowles. You need either fice if commands. Use lower() tocatch the uppercase characters also. ismember would be easier. Or look at this:
'a' == 'nabvdsh'
This together the the any() command would be cheaper than the suggested strcmp(). Finally use disp() to display a character.
More Answers (3)
Walter Roberson on 24 Feb 2017
"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."
No, that is not correct.
Consider "yellow" and "yip" and "cry" and "ytterbium"
"y" is called a "semi-vowel". There are other semi-vowels used in English that might have different rules. "w" is also considered a semi-vowel, but not (for example) in "vowel" or "cow"; notice the completely different "w" sound in "won" and "when".
"w" is also a semi-vowel, and acts like a vowel in situations such as "won" (followed by a short vowel), "wine" (followed by a long vowel), and "when" (followed by an "h" followed by a vowel.) But "w" does not act as a vowel in the word "vowel" nor in "how".
"cry" is a good example of a situation in which you cannot escape the situation by saying "Oh, but it is not the real vowel in the word, the real vowel is ..." -- a claim you might make for "yip" for example. There is no other vowel than "y" in "cry".
It is therefore not possible to detect vowels by examining one letter at a time.
Do not neglect â à ä å ê è ì ö ü á ắ ấ ǻ é ế í ḯ ó ő ớ ṍ ǿ ú ű ứ ý æ ǽ or Latin Capital A with Stroke
sehar siddique on 10 Jul 2019
can i have complete method or code or software that how to get vowels from speech signal (urdu language) in matlab ??
Mohammed Hamaidi on 20 Jan 2022
my_sentence=input('Please enter a sentence: ','s');
m=['Y','W','R','H','Z ','X','V','T','S','Q','P','N','M','L','K','J','G','F','D','C','B'];%your can remove 'Y'
s1=s1(m(i) ~= upper(s1));