SUBSTRINGS CREATION WITH DIFFERENT ORDER

1 回表示 (過去 30 日間)
FRANCISCO
FRANCISCO 2013 年 11 月 21 日
コメント済み: Azzi Abdelmalek 2013 年 11 月 21 日
I wish to estimate substrings of length 4-13, a primary secuence currently about 150,000 binary numbers. How to create the substrings be as follows:
let's assume we have the following sequence (numbers in parentheses indicate the order):
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)
substrings of length 4 would be:
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) .
Now would do the same with the substrings of length 5 After substrings of length 6 ..... up length 13
Many thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 21 日
編集済み: Azzi Abdelmalek 2013 年 11 月 21 日
s =[ 0 1 1 0 1 1 0 1 0 0 0 1 ];
n=6;
m=numel(s)-n+1;
A=zeros(m,n);
idx=cell2mat(arrayfun(@(x) x:x+n-1,(1:m)','un',0));
out=s(idx)
  4 件のコメント
FRANCISCO
FRANCISCO 2013 年 11 月 21 日
okei, for example we have the following sequence:
  s = [0 0 0 0 0 0 0 0 0 1];
I apply the code you created to create substrings of length 4:
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
and the result of "out" is:
      0 0 0 0
      0 0 0 0
      0 0 0 0
      0 0 0 0
      0 0 0 0
      0 0 0 0
      0 0 0 1
we see that the pattern [0 0 0 0] has been repeated 6 times. How would that "out" out:
[0 0 0 0] | 6
[0 0 0 1] | 1
Thank you very much.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 21 日
s =[ 0 1 1 0 1 1 0 1 0 0 0 1 ];
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)
[a,b,c]=unique(out,'rows','stable')
freq=accumarray(c,ones(size(c)))
[a freq]

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 21 日
編集済み: Andrei Bobrov 2013 年 11 月 21 日
s = [0 1 1 0 1 1 0 1 0 0 0 1 ];
n = numel(s);
k=4:n;
out = cell(n-3,1);
for jj = 1:numel(k)
p = s(hankel(1:k(jj),k(jj):n)');
[p2,~,ii] = unique(p,'rows');
out{jj} = [p2, accumarray(ii,1)];
end

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by