Delete letters in a string variable

62 ビュー (過去 30 日間)
Zheng
Zheng 2013 年 5 月 31 日
コメント済み: Erfan Askarzadeh 2022 年 3 月 2 日
Hi,
for instance, string variables are '2456.00A', '2501A',...
How can I delete letters in a string variable?
Thanks in advance.

採用された回答

Jonathan Sullivan
Jonathan Sullivan 2013 年 5 月 31 日
To detect which charectors are letters, you can use the function isletter. Then just simply delete the ones that are letters
Example:
yourString = '2456.00A';
deleteMe = isletter(yourString); % Detect which ones are letters
yourString(deleteMe) = []; % Delete the letters
disp(yourString) % Display the result
  1 件のコメント
Erfan Askarzadeh
Erfan Askarzadeh 2022 年 3 月 2 日
Thanks.

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 31 日
編集済み: Azzi Abdelmalek 2013 年 5 月 31 日
s={'2456.00A', '2501A'};
out=cellfun(@(x) x(regexp(x,'[^a-zA-Z]')),s,'un',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