Thread Subject: Explicit Looping

Subject: Explicit Looping

From: Rafael

Date: 7 Nov, 2009 09:13:02

Message: 1 of 3

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')
else
    
    
    for i=location:cols
        if motif==protein(i)
            a=1;
        
        end
    end
end

Subject: Explicit Looping

From: dpb

Date: 7 Nov, 2009 14:14:01

Message: 2 of 3

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...

--

Subject: Explicit Looping

From: dpb

Date: 7 Nov, 2009 14:26:50

Message: 3 of 3

dpb wrote:
...
> Your problem is fully specified ...

dang! That was _NOT_ fully specified, of course, intended...

--

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
for Rafael 7 Nov, 2009 04:14:06
loops Rafael 7 Nov, 2009 04:14:06
while Rafael 7 Nov, 2009 04:14:06
bioinformatics Rafael 7 Nov, 2009 04:14:06
explicit looping Rafael 7 Nov, 2009 04:14:05
rssFeed for this Thread

Contact us at files@mathworks.com