"contains" with multiple conditions
조회 수: 63 (최근 30일)
이전 댓글 표시
Hi, I have the following code
A = "159 ( 51,1%) 13 (4,2% ) 139 (44,7%)";
A = textscan(A,'%s','Delimiter',' ')';
A{:}(contains(A{:},'(')) = [];
A{:}(contains(A{:},')')) = [];
A{:}(contains(A{:},'%')) = [];
which removes all the brackets and the numbers between the brackets (in this case they are percentages):
% Result after "textscan" (just typing A{:})
8×1 cell array
{'159' }
{'(' }
{'51,1%)' }
{'13' }
{'(4,2%' }
{')' }
{'139' }
{'(44,7%)'}
% Result after all the "contains" (just typing A{:})
3×1 cell array
{'159'}
{'13' }
{'139'}
However, I would like to use one single command for contains with multiple conditions. Would it be possible?
Something like this:
% Input
A{:}(contains(A{:},['(' OR ')' OR '%')) = [];
% Desired output
A = "159 13 139";
댓글 수: 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!