フィルターのクリア

is there a more efficient way to omit certain characters from a string without using loops?

1 回表示 (過去 30 日間)
Hello. I have to take out characters from a string. I am using strrep. :
newsf = strrep(sf, 'C', '');
newsf = strrep(newsf, 'R', ''); n ewsf = strrep(newsf, 'E', '');
newsf = strrep(newsf, 'P', ''); newsf = strrep(newsf, 'SQ', '');
newsf = strrep(newsf, '1', '');
newsf = strrep(newsf, '2', '');
newsf = strrep(newsf, '3', '');
newsf = strrep(newsf, '4', '');
etc
I have tried using ~= for the characters I want but it won't accept that. Thanks for your time

採用された回答

Cedric
Cedric 2013 年 5 月 2 日
編集済み: Cedric 2013 年 5 月 2 日
One way would be
newsf = regexprep(sf, '([CREP1-4]|SQ)', '') ;
but what does "etc" encompass?
  2 件のコメント
Brian
Brian 2013 年 5 月 2 日
Thank you sir, that's brilliant. Sorry, I meant the rest of possible numeric values. 0-9 worked, thanks again
Cedric
Cedric 2013 年 5 月 2 日
編集済み: Cedric 2013 年 5 月 2 日
Great, you're welcome!

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

その他の回答 (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