the first letter of the output string will be the first letter of the first word of the sentence.

1 回表示 (過去 30 日間)
Whose input is a sentence (as a string). The words of the sentence are separated by single blanks, and there is a dot at the end of the sentence. The output will be a word (as a string) created by alternatingly picking the first and last letters of the words of the sentence:
The first letter of the output string will be the first letter of the first word of the sentence. The second letter of the output string will be the last letter of the second word. The third letter will be the first letter of the third word, and so on. (You may NOT use any built-in functions except size, length, rem and mod)
Example:
If Sentence= 'The tree nut sings in no need.'
and Out = first_last_letters (Sentence)
Out will be Out='Tension'

採用された回答

Rohith Nomula
Rohith Nomula 2020 年 6 月 9 日
編集済み: Rohith Nomula 2020 年 6 月 9 日
You can split your string using a delimiter. which in your case is space
new_s = split(s,' ')
create a dummy string ans and append the required fields
Run a loop on new_s so that you can access first and last chars as follows
% for odd index string
ans = append(ans,new_s{i}(1))
% for even index string
ans = append(ans,new_s{i}(end))
Try this !
  3 件のコメント

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

その他の回答 (0 件)

カテゴリ

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