Azzera filtri
Azzera filtri

How to delete a substring within a string

2 visualizzazioni (ultimi 30 giorni)
JB
JB il 28 Ago 2017
Commentato: Jan il 28 Ago 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 Commento
Jan
Jan il 28 Ago 2017
You do not delete a "substring" from a "string", but specific "cell elements", which are a scalar cell string containing the empty string.

Accedi per commentare.

Risposta accettata

James Tursa
James Tursa il 28 Ago 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.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by