I have a string that is going to keep updating
Say x='ear' how do I take the last later in the string so say lastletter='r' is it possible to have this work generally to always take the last later in a the string so say x gets updated to 'eart' lastletter=-t'

 採用された回答

Thorsten
Thorsten 2015 年 11 月 11 日

1 投票

x = 'ear';
lastletter = x(end);

3 件のコメント

ABDALHADI ABU ZEYNEH
ABDALHADI ABU ZEYNEH 2020 年 5 月 22 日
if x=dbacdcbad,how can i pick all the a's and c's so that the answer is ''acca''?
thank you in advance
Justin
Justin 2023 年 10 月 25 日
編集済み: Justin 2023 年 10 月 25 日
AllA = x(x == "a")
I have not tested this, just a belief this works
Walter Roberson
Walter Roberson 2023 年 10 月 25 日
No that would not work. When you use == to compare a character vector to a string scalar, the character vector gets converted to a string scalar and then the == would be comparing for string equality not character equality.
On the other hand
x(x == 'a')
would pull out all of letter 'a'

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

Max
2015 年 11 月 11 日

コメント済み:

2023 年 10 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by