How to Count occurrences?
조회 수: 2 (최근 30일)
이전 댓글 표시
Given a text: ‘tagtacagccagtagagttgattccaaggaagtccggctgttgtagagtagc’ and a three-character target pattern (for example: ‘TAG’ ), your program should identify all target patterns in the text and output the number of occurrences of the target pattern.
Sample output Text:tagtacagccagtagagttgattccaaggaagtccggctgttgtagagtagctag
Target:TAG
Number of TAG:5
Target:tag
Number of tag:5
Target:GTa
Number of cag:2
Target:exit Program terminated!
댓글 수: 3
Priyadharshini A.R
2021년 5월 10일
Hello Dabney,
The loop must go on till n-m+1 so that it can traverse till last element in text
답변 (2개)
Jan
2021년 5월 10일
t = 'tagtacagccagtagagttgattccaaggaagtccggctgttgtagagtagc';
tag = 'tag';
result = sum(strfind(lower(t), lower(tag)))
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!