How to delete a substring within a string

조회 수: 2 (최근 30일)
JB
JB 2017년 8월 28일
댓글: Jan 2017년 8월 28일
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