Remove cells that contain only two or one character

1 次查看(过去 30 天)
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