MATLAB Answers

How to delete a substring within a string

조회 수: 4(최근 30일)
JB 28 Aug 2017
Commented: Jan 28 Aug 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

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

로그인 to comment.

채택된 답변

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

  댓글 수: 0

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by