Trouble displaying the final count
1 回表示 (過去 30 日間)
古いコメントを表示
Hi all, I am having trouble with a portion of my code. I have created this code to search through a character array of DNA and pick out how many time the sequence CAT appears. The code works fine and displays the correct answer, however i need it not to show the count from 1-126 but just the final count at 126. Thanks for the help! Code is located below
load HW2_part2_data.mat
count = 0;
for i = 1: length(DNA)-1
if DNA(i,1)=='C'
if DNA(i+1,1)=='A'
if DNA(i+2,1)=='T'
count = count + 1;
end
end
end
end
1 件のコメント
TADA
2019 年 2 月 13 日
編集済み: TADA
2019 年 2 月 13 日
Not sure I understand what you mean
but you have a bug in your loop index, you need to stop at length(DNA)-2.
Moreover, you can replace the loop with a simpler strfind if your DNA vector would be a row vector instead:
% generate random DNA sequence
bases = 'ATGC';
DNA = bases(randi(4, 400, 1));
% cound number of CAT sequences in the DNA chain
count = numel(strfind(DNA, 'CAT'));
採用された回答
Kevin Phung
2019 年 2 月 13 日
編集済み: Kevin Phung
2019 年 2 月 13 日
just do this:
search = 'CAT';
locate = regexp(DNA,search)
count = numel(locate{1}) %number of times CAT appears
edit: it seems like by the time I made the edit above, you accepted my previous answer which i thought was wrong. So i'll just repost it just in case both come in handy:
Prev soln:
sum(contains(DNA,'CAT'))
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Genomics and Next Generation Sequencing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!