How to delete a substring within a string

1 visualización (últimos 30 días)
JB
JB el 28 de Ag. de 2017
Comentada: Jan el 28 de Ag. de 2017
I have a string like this
a={ {'a', 'b', 'c','d'},{''}, {'e', 'f', 'g', 'h'},{''} }
where the two '' are empty {1x1 cell} substrings within the string. How do I delete empty substring like this and end up with
a={ {'a', 'b', 'c','d'}, {'e', 'f', 'g', 'h'} }
  1 comentario
Jan
Jan el 28 de Ag. de 2017
You do not delete a "substring" from a "string", but specific "cell elements", which are a scalar cell string containing the empty string.

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 28 de Ag. de 2017
Assuming the cells to be deleted are all of the form {''}, you could simply use the isequal function. E.g.
x = cellfun(@(y)isequal(y,{''}),a);
a(x) = [];
If there could be other forms of elements that you would consider "empty", you would need to tell us what that could be.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by