wilcard usage with strncmp
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a cell array data (C). I use the following code to find specific character in the C;
find_character = strncmp(C, '* 2020', 7);
How can I use wilcard using strncmp to find all patterns satisfy * [0-9][0-9][0-9][0-9]? For example, if * 1988 or * 2000 exist in C, they can be also extracted.
댓글 수: 0
채택된 답변
Stephen23
2021년 5월 16일
C = {'hello','* 2020','world','* 1923'};
X = ~cellfun(@isempty,regexp(C,'^\* \d{4}$'))
D = C(X)
댓글 수: 4
Stephen23
2021년 5월 16일
"How I can modify the above codes to work consistently with my cell array."
Remove the '$' from the end of the regular expression:
C = {'hello','* 2020 3 28','world','* 1923'};
X = ~cellfun(@isempty,regexp(C,'^\* \d{4}'))
추가 답변 (1개)
Image Analyst
2021년 5월 16일
Use the pattern functionality. I think it's easier than regexp().
>> doc pattern
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!