Creating array from binary sequence, and certainly with the calculation of the dimension

1 view (last 30 days)
I have this sequence:
0 (1) 0 (2) 0 (3) 1 (4) 1 (5) 0 (6) 0 (7) 0 (8) 0 (9) 0 (10) 1 (11) 0 (12)
0 (13) 0 (14) 0 (15) 1 (16) 0 (17) 0 (18) 1 (19) 1 (20).
As I can create an array like this in general, ie can perform instead of substrings of length 3, 4,5,6 .... too long? I have doubt through command for creating the dimension of the matrix, and I want you to believe me automatically. The matrix example is:
0 (18) 1 (19) 1 (20)
0 (15) 0 (17) 1 (19)
0 (12) 0 (15) 0 (18)
0 (9) 0 (13) 0 (17)
0 (6) 1 (11) 1 (16)
0 (3) 0 (9) 0 (15)
  2 Comments
FRANCISCO
FRANCISCO on 26 Sep 2013
I from the first sequence of data, I want to create an array with that order. No nx3 always no, I have posibildad nX4, nX5, nX6 ........ How could I do?

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 26 Sep 2013
Edited: Azzi Abdelmalek on 26 Sep 2013
A=randi([0 1],1,30); % your array
m=5; % the result will be nx5
n=numel(A);
p=n-m+1:-m:1;
np=numel(p);
B=zeros(np,m);
B(:,1)=p';
mm=m;
for k=2:m
mm=mm-1;
B(:,k)=(n-m+k:-mm:n-m+k-mm*(np-1))';
end
disp(B) % matrix of indices
out=A(B)

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!