CALCULATION SUBSTRINGS OF MATRIZ SEQUENCES

1 次查看(过去 30 天)
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

采纳的回答

Andrei Bobrov
Andrei Bobrov 2013-11-22
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 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by