From: dpb <none@non.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Explicit Looping
Date: Sat, 07 Nov 2009 08:14:01 -0600
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <hd3vbf$jcg$1@news.eternal-september.org>
References: <hd3dmu$k1n$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.eternal-september.org U2FsdGVkX192ehZRG0diNcmAM9hLSlJ8OFrUPEuvufmft4tZMvkvhA878a42sJLvKIEmVn1FzcwXFPM1ZCEw9cXyPd/o66oHUoPRs8u3hiFF40yLUdLkigF9HQJyWxIj3kcTsZrSGzE=
X-Complaints-To: abuse@eternal-september.org
NNTP-Posting-Date: Sat, 7 Nov 2009 14:14:08 +0000 (UTC)
In-Reply-To: <hd3dmu$k1n$1@fred.mathworks.com>
X-Auth-Sender: U2FsdGVkX1+UNBYSDBMFnIxmLAzwwKeQOR2qhCpsfGA=
Cancel-Lock: sha1:KhbhTvuADNqDwd/4V8qnOpMGVcI=
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
Path: news.mathworks.com!newsfeed-00.mathworks.com!oleane.net!oleane!feed.ac-versailles.fr!gegeweb.org!feeder.eternal-september.org!eternal-september.org!not-for-mail
Xref: news.mathworks.com comp.soft-sys.matlab:583220


Rafael wrote:
> I am trying to write a function that will that take a random
> assortment of numbers (motif) and if the 'motif' is in the designated
> location of the longer chain of random numbers (protein), it will return
> as "1" or "true." Otherwise, it will return as "0". I'm not entirely
> familiar with how for works but here is my coding so far. I think it's
> on the right track; does anybody know what I did wrong.
> 
> Thanks so much!
> 
> 
> function a=Motif_Match(motif,protein,location)
> [rows cols]=size(protein);
> if rows~=1
>     disp('motif_match only accepts vectors')

minor detail...

Do you really only want row vector or wouldn't a column vector be just 
as useful?

I'd suggest also when end w/ the error condition use error() instead of 
disp() to abort since there's no point in going on anyway (and as you've 
written it, it in effect does the same thing except you could 
encapsulate the error stuff up front and eliminate the rest of the code 
inside the conditional).

if rows~=1
   error('motif_match only accepts vectors')
end


...
> for i=location:cols
>   if motif==protein(i)
>     a=1;
>   end
> end

Your problem is fully specified -- what's the location of the required 
match in the protein vector and what's the length of motif?

What is the range of the numeric values?  It might be easier to convert 
to a character representation and do a findstr() operation.

Need more poop...

--