Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 26 Sep. 2013
Bearbeitet: Azzi Abdelmalek am 26 Sep. 2013
Your question is not clear. Is the matrix you want to create always an nx3 size?
FRANCISCO
FRANCISCO am 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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 26 Sep. 2013
Bearbeitet: Azzi Abdelmalek am 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)

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by