フィルターのクリア

How would i adapt this code to make it work for a whole phrase, not just one word?

1 回表示 (過去 30 日間)
Charlotte Reed
Charlotte Reed 2020 年 3 月 19 日
コメント済み: Walter Roberson 2020 年 3 月 20 日
function out = word2piglatin
word = input ( 'Enter a word:' , 's' );
% Check if the first letter of the word is vowel or not
if ismember(word(1), 'aeiouAEIOU' )
out = [word 'way' ]; %Append 'way' to the word
else
out= [word(2:end) word(1) 'ay' ]; %Place the starting letter at the end and append the 'ay'
end
end
  10 件のコメント
Rik
Rik 2020 年 3 月 20 日
In your code you didn't cut up the phrase into words.
Walter Roberson
Walter Roberson 2020 年 3 月 20 日
Is "e-mail" one word or two?
How many words is "nonetheless"?

サインインしてコメントする。

回答 (1 件)

John D'Errico
John D'Errico 2020 年 3 月 19 日
Simplest would be to extract each word, one at a time. For example, consider this sentence (taken from your question):
phrase = 'Check if the first letter of the word is vowel or not';
w = strsplit(phrase)
w =
1×12 cell array
Columns 1 through 11
{'Check'} {'if'} {'the'} {'first'} {'letter'} {'of'} {'the'} {'word'} {'is'} {'vowel'} {'or'}
Column 12
{'not'}
Now you can just loop over the words as found. Apply the piglatin rules to each word. Be careful if there is punctuation.
I could have dome it similarly by using the function strtok.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by