필터 지우기
필터 지우기

remove occurrences of given characters in a string using find and []

조회 수: 4 (최근 30일)
Britnie Casillas
Britnie Casillas 2019년 10월 26일
댓글: Britnie Casillas 2019년 10월 26일
function f=test(s,c)
f=regexp(find(s=='c'))=[];
end
my s='now is the time for all good'
I am trying to remove all the o's in the sentence. However, when I go to test it I get an error with the second eqal sign --> =[];
it says incorrect use of '=' operator. However, when I try to change it, i still get the same error.

채택된 답변

ME
ME 2019년 10월 26일
편집: ME 2019년 10월 26일
If you absolutely have to use find then you could use
function f=test(s,c)
idx=find(s==c);
s(idx)=[];
f=s;
end
Or, you could simplify it by using regular expressions instead:
function f=test(s,c)
f= regexprep(s,c,'')
end

추가 답변 (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