As I can solve the following problem binary

7 ビュー (過去 30 日間)
FRANCISCO
FRANCISCO 2013 年 10 月 24 日
回答済み: Andrei Bobrov 2013 年 10 月 31 日
Yo tengo la siguiente secuencia binaria:
s=[1(1) 1(2) 1(3) 0(4) 1(5) 0(6) 0(7) 0(8) 0(9) 1(10) 1(11) 4(12)];
y quiero que me realice calcule las substrings de longitud n=4 de la siguiente manera:
1(9) 1(10) 1(11) 4(12)
0(6) 0(8) 1(10) 4(12)
1(3) 0(6) 1(9) 4(12)
He de decir que la longitud de las substrings deben poder modificarse, al igual que la longitud de la secuencia.
Muchas gracias
  2 件のコメント
sixwwwwww
sixwwwwww 2013 年 10 月 24 日
Can you please translate your question in english?
FRANCISCO
FRANCISCO 2013 年 10 月 24 日
sorry,
I have the following binary sequence:
s = [1 (1) 1 (2) 1 (3) 0 (4) 1 (5) 0 (6) 0 (7) 0 (8) 0 (9) 1 (10) 1 (11) 4 (12 )];
and do I want to calculate the substrings of length n = 4 in the following way:
1 (9) 1 (10) 1 (11) 4 (12)
0 (6) 0 (8) 1 (10) 4 (12)
1 (3) 0 (6) 1 (9) 4 (12)
I must say that the length of the substrings must be changeable, like the length of the sequence.
thank you very much

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

採用された回答

sixwwwwww
sixwwwwww 2013 年 10 月 24 日
Dear FRANCISCO, here is the code which performs the desired function:
s = 1:100; % Your array
n = 11; % Length of sub-arrays
a = fliplr(s);
combinations = floor(length(s) / n);
b = zeros(combinations, n);
for k = 1:combinations
b(k, 1) = a(1);
l = 1;
for j = 1:n - 1
l = l + k;
b(k, j+1) = a(l);
end
end
Matrix_combinations = fliplr(b);
disp(Matrix_combinations) % Final matrix of sub-arrays
I hope it helps. Good luck!

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 10 月 31 日
n = 4;
idxend = 12;
idx = idxend + bsxfun(@times,1-n:0,(1:n-1)');

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by