Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 26 Sep 2013
Modifié(e) : Azzi Abdelmalek le 26 Sep 2013
Your question is not clear. Is the matrix you want to create always an nx3 size?
FRANCISCO
FRANCISCO le 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?

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 26 Sep 2013
Modifié(e) : Azzi Abdelmalek le 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)

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by