필터 지우기
필터 지우기

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by