필터 지우기
필터 지우기

Remove cells that contain only two or one character

조회 수: 1 (최근 30일)
KnowledgeSeeker
KnowledgeSeeker 2014년 3월 11일
편집: Andrei Bobrov 2014년 3월 11일
I have a variable that contain large cell arrays of strings but some of the cells contains strings that are meaningless such asç
xx = {'animal','a','aa','bc','dog','car','computer','screen','zx','tt','c','pen','ss'}
I would like to use regexp but I couldnt find appropriate expression to match two or single character.
Any sugguestion is highly appreciated.
Sami

채택된 답변

Chandrasekhar
Chandrasekhar 2014년 3월 11일
편집: Chandrasekhar 2014년 3월 11일
len = length(xx)
cnt = 1;
for i = 1:len
str = char(xx(cnt))
if(length(str)==1 || length(str)==2)
xx(cnt) = [];
len = length(xx);
else
cnt= cnt+1;
end
end

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 3월 11일
편집: Andrei Bobrov 2014년 3월 11일
xx = {'animal','a','aa','bc','dog','car','computer','screen','zx','tt','c','pen','ss'}';
out = xx(cellfun(@numel,xx) <= 2)
:)
out = xx(cellfun(@numel,xx) > 2)
  댓글 수: 1
KnowledgeSeeker
KnowledgeSeeker 2014년 3월 11일
편집: KnowledgeSeeker 2014년 3월 11일
Thank you for the sugustion but this line only finds the cells that contain one or two strings without removing them from the original data

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by