How to delete a substring within a string

2 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-8-28
You do not delete a "substring" from a "string", but specific "cell elements", which are a scalar cell string containing the empty string.

请先登录,再进行评论。

采纳的回答

James Tursa
James Tursa 2017-8-28
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by