|
"Justin " <riley127099@yahoo.com> wrote in message
news:hdat28$6qk$1@fred.mathworks.com...
> Objective: Trying to write a function that pinpoints the location at which
> a smaller chain of letters "ex. 'AB' " appears in a longer chain of
> letters "ex. 'BCDCABDEDAB' " and therefore, the function would return 5
> and 10. Here's my coding for the function.
> Any of matlab's built-in functions are not allowed. Only explicit looping
> can be used.
You cannot complete the assignment with these restrictions, as I believe I
said before (although it could have been in response to a different poster.)
> PART I
> function a=Motif_Match(motif,protein,location)
> [rows cols]=size(protein);
You've already broken the restriction. The SIZE function is a built-in
function and so cannot be used, by the terms of the assignment.
> i=location:location+length(motif)-1; %cut the protein vector into the
COLON ( : ), LENGTH, PLUS and MINUS are also all built-in functions.
> %same length as the motif vector given the input location
> if rows~=1
NE (for Not Equals, or ~=) is also built-in.
> disp('motif_match only accepts vectors') %Error checking; proteins can
> not have multiple rows.
DISP.
> elseif motif==protein(i) %protein of length of motif, starting at
> designated location, must be the
EQ (==), and if you want to get technical SUBSREF for the subscripted
referencing.
> %same as motif to be true.
> a=1;
> else a=0; %if the aforementioned conditions do not apply, then the
> statement is false
> end
IF, ELSEIF, and ELSE are keywords, so I guess they're okay, and assignment
isn't really a built-in function ... but other than that you've used plenty
of built-in functions in your code above.
If Justin's teacher/professor is reading -- you've given your student an
impossible task.
Assuming you're only prohibited from using the STRFIND built-in function and
similar string-manipulation functions (with which this assignment would be a
two-liner) your code above is pretty close. I wouldn't use == in this case,
though; there's another function that will tell you if one string IS EQUAL
to another.
Alternatly, if FIND is allowed, there's a small shortcut you can use to
limit the number of locations you have to check.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|