CALCULATION SUBSTRINGS OF MATRIZ SEQUENCES
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
FRANCISCO
el 21 de Nov. de 2013
Respondida: Andrei Bobrov
el 22 de Nov. de 2013
Using the following code, I made a substrings of sequence. For example, i have the next sequence:
s = 0 (1) 1 (2) 1 (3) 0 (4) 1 (5) 1 (6) 0 (7) 1 (8) 0 (9) 0 (10) 0 (11) 1 (12)
(Numbers in parentheses indicate the order only) and applying the following code:
if true
% code
n=4;
m=numel(s)-n+1;
A=zeros(m,n);
idx=cell2mat(arrayfun(@(x) x:x+n-1,(1:m)','un',0));
out=s(idx)
end
I get:
0 (1) 1 (2) 1 (3) 0 (4)
1 (2) 1 (3) 0 (4) 1 (5)
1 (3) 0 (4) 1 (5) 1 (6)
0 (4) 1 (5) 1 (6) 0 (7)
1 (5) 1 (6) 0 (7) 1 (8)
1 (6) 0 (7) 1 (8) 0 (9)
0 (7) 1 (8) 0 (9) 0 (10)
1 (8) 0 (9) 0 (10) 0 (11)
0 (9) 0 (10) 0 (11) 1 (12)
But if instead of having a sequence, I have an array of sequences, as calculated the substrings of all sequences of the matrix, and store all of the substring in other matrix?
For example,
0 1 1 0 1 1 0 1 0 0 0 1
0 1 1 1 1 1 0 1 1 0 0 0
Many thanks
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 22 de Nov. de 2013
s = [0 1 1 0 1 1 0 1 0 0 0 1;
0 1 1 1 1 1 0 1 1 0 0 0];
sz = size(s);
k = 4;
s1 = s';
idx = bsxfun(@plus,hankel(1:k,k:sz(2))',reshape(sz(2)*(0:sz(1)-1),1,1,[]));
out = s1(idx);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre String en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!