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
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.
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.