Azzera filtri
Azzera filtri

Finding vowels in a string the user inputs and printing the vowels. Here's the problem:

16 visualizzazioni (ultimi 30 giorni)
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.
  4 Commenti
Jan il 24 Feb 2017
Modificato: Jan il 24 Feb 2017
I've tagged this as "homework" because it sounds like it is one. Then posting a complete answer would be counterproductive, because 1. you cannot deliver it without cheating anymore and 2. encouraging you to find the solution by your own will let you learn more.
Steven Lord
Steven Lord il 24 Feb 2017
Reread the assignment carefully. It lists two MATLAB functions that you should use. One of those functions will be useful to "compare a string that the user inputs to a vowel". The only other hint I'll give you is that you may need to call that function multiple times and combine the results: 5 (or 6, depending on your definition of vowel) times.

Accedi per commentare.

Risposta accettata

Jan il 24 Feb 2017
The question mentions all tools reuiqred for the solution already:
  1. input
  2. loop
  3. strcmp
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.

Più risposte (3)

Walter Roberson
Walter Roberson il 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
  1 Commento
Walter Roberson
Walter Roberson il 10 Ott 2017
There are also some fairly uncommon words in English, mostly derived from Old English or from Welsh, in which "w" is acting as the only vowel, not just something that could be classified as "modifying a vowel", similar to the way that "y" is acting as the only vowel in "cry". suggests “Cwm” (a steep-walled semicircular basin in a mountain, sometimes containing a lake; a cirque) and “crwth” (an ancient Celtic musical instrument).
That page indicates that l, m, n, and r sometimes represent vowels in English -- that is, that their presence indicates a dipthong (a combination of letters that is together pronounced a different way than just putting the letters together.)

Accedi per commentare.

sehar siddique
sehar siddique il 10 Lug 2019
can i have complete method or code or software that how to get vowels from speech signal (urdu language) in matlab ??

Mohammed Hamaidi
Mohammed Hamaidi il 20 Gen 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'
for i=1:21
s1=s1(m(i) ~= upper(s1));


Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by