On 7/5/2013 11:15 AM, Fogato Abbestia wrote:
> for example
>
> seq = 'atcggttaat'
> k=3;
>
> i want as output
>
> word={'atc' 'tcg' 'cgg' 'ggt' 'gtt' 'tta' 'taa' 'aat'}
>
...
OK, so it is length k and does step by a single character not the
pattern length...let's see...
Brute force--
N=length(seq)-(k-1); % number of tokens possible
word=cell(1,N);
for i=1:N
word(i)={seq(i:i+k-1)};
end
Vectorized...hmmm....oh, ok, try this--
word=seq(cumsum([[1:k];ones(length(seq)-k,k)]));
This will return a column vector rather than row vector if that's alright...
--
> for example
>
> seq = 'atcggttaat'
> k=3;
>
> i want as output
>
> word={'atc' 'tcg' 'cgg' 'ggt' 'gtt' 'tta' 'taa' 'aat'}
>
...
OK, so it is length k and does step by a single character not the
pattern length...let's see...
Brute force--
N=length(seq)-(k-1); % number of tokens possible
word=cell(1,N);
for i=1:N
word(i)={seq(i:i+k-1)};
end
Vectorized...hmmm....oh, ok, try this--
word=seq(cumsum([[1:k];ones(length(seq)-k,k)]));
This will return a column vector rather than row vector if that's alright...
--