Borrar filtros
Borrar filtros

Remove cells that contain only two or one character

1 visualización (últimos 30 días)
KnowledgeSeeker
KnowledgeSeeker el 11 de Mzo. de 2014
Editada: Andrei Bobrov el 11 de Mzo. de 2014
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

Respuesta aceptada

Chandrasekhar
Chandrasekhar el 11 de Mzo. de 2014
Editada: Chandrasekhar el 11 de Mzo. de 2014
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

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 11 de Mzo. de 2014
Editada: Andrei Bobrov el 11 de Mzo. de 2014
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 comentario
KnowledgeSeeker
KnowledgeSeeker el 11 de Mzo. de 2014
Editada: KnowledgeSeeker el 11 de Mzo. de 2014
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

Iniciar sesión para comentar.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by