I have built a function to be run 100000 times in a loop. Its input, "motifs", is a full 20×15 char array, containing only four types of characters, 'A', 'C', 'G', 'T'. I am wondering if my implementation, below, can be improved of if it is pretty much as fast as it gets:
% Find consensus string and score of a motifs array
function [score, count, consensus] = scoremotifs_2(motifs)count = [ sum(motifs == 'A',1) ; sum(motifs == 'C',1) ; sum(motifs == 'G',1) ; sum(motifs == 'T',1) ]; [count_max, consensus_num] = max(count);consensus(consensus_num == 1) = 'A';consensus(consensus_num == 2) = 'C'; consensus(consensus_num == 3) = 'G';consensus(consensus_num == 4) = 'T';score = sum(sum(motifs ~= consensus));
Best Answer