Hi there, I want to delete any character which repeated more than 3 in string I have this code which delete all repatriation Input = {'CEEEGH';'CCEEG';'ABCDEFF';'BCFGG';'BCDEEG';'BEFFH';'AACEGH'}
cellfun(@unique,Input,'UniformOutput',0)

댓글 수: 2

James Tursa
James Tursa 2016년 10월 13일
Delete characters that repeat more than 3 times total, or more than 3 times in a row?
Jos (10584)
Jos (10584) 2016년 10월 13일
What is the output supposed to look like?

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

답변 (1개)

Gautam Mohan
Gautam Mohan 2016년 10월 18일

0 개 추천

Hi Ebtesam,
If you want to delete any character which is repeated three or more times in a row, you can substitute the @unique function in your cellfun() with a regexp that searches for 3+ character matches and replaces them with nothing:
f = @(s) regexprep(s, '(\S)\1\1+', '');
cellfun(f,Input,'UniformOutput',0)
If you need to eliminate characters that occur 3 or more times throughout the whole string, I would recommend writing a separate function that accomplishes that goal and then applying it to each string using cellfun().
Hope this helps!

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2016년 10월 13일

답변:

2016년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by