CALCULATION SUBSTRINGS OF MATRIZ SEQUENCES
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
FRANCISCO
am 21 Nov. 2013
Beantwortet: Andrei Bobrov
am 22 Nov. 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 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 22 Nov. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu String finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!