How to Count occurrences?
Ältere Kommentare anzeigen
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 Kommentare
Guillaume
am 8 Okt. 2019
So? It's trivial to do with strfind in just one short line of code.
What effort, if any, have you made?
Cre'Shawn Dabney
am 8 Okt. 2019
Priyadharshini A.R
am 10 Mai 2021
Hello Dabney,
The loop must go on till n-m+1 so that it can traverse till last element in text
Antworten (2)
Jan
am 10 Mai 2021
t = 'tagtacagccagtagagttgattccaaggaagtccggctgttgtagagtagc';
tag = 'tag';
result = sum(strfind(lower(t), lower(tag)))
Alaster Meehan
am 8 Okt. 2019
0 Stimmen
strcmpi ignors case
Cheers Alaster
1 Kommentar
Cre'Shawn Dabney
am 8 Okt. 2019
Kategorien
Mehr zu Common Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!