How to delete a substring within a string

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 Comment

You do not delete a "substring" from a "string", but specific "cell elements", which are a scalar cell string containing the empty string.

Sign in to comment.

 Accepted Answer

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.

More Answers (0)

Categories

Products

Asked:

JB
on 28 Aug 2017

Commented:

Jan
on 28 Aug 2017

Community Treasure Hunt

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

Start Hunting!