Path: news.mathworks.com!not-for-mail
From: "Justin " <riley127099@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Explicit Loops
Date: Sun, 8 Nov 2009 23:22:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <hd7jqq$1h4$1@fred.mathworks.com>
Reply-To: "Justin " <riley127099@yahoo.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257722522 1572 172.30.248.38 (8 Nov 2009 23:22:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 8 Nov 2009 23:22:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1995558
Xref: news.mathworks.com comp.soft-sys.matlab:583428


What I want to do is write a function that will return all locations at which a random chain of letters appears in a longer chain of letters. So if the smaller chain of random letter, "motif" is aar and the longer chain, "protein" is abbdaardkadaar, the function will return the location  of aar at 5 and 12. Here's what I have so far, but something is off. I would really appreciate some assistance. Thank so much!

function loc=Motif_Find(motif,protein)
c=double(motif);
d=double(protein);
[rows cols]=size(d);
if rows~=1
    disp('motif_match only accepts vectors') %Error checking; proteins can not have multiple rows.
loc=[];
else
    a=1:length(c);
    while d(a)~=c
        loc=a+1;
        if d(loc)==c
            disp(loc(1))
            break
        end
    end
end