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
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!