Effacer les filtres
Effacer les filtres

How to create such a matrix like this?

1 vue (au cours des 30 derniers jours)
Taner Cokyasar
Taner Cokyasar le 13 Juil 2016
Commenté : Taner Cokyasar le 13 Juil 2016
Hello,
I need to create a matrix as following:
Number of the rows depend on 'i', where i=3 and number of columns depend on i*s, where s=12 in this example.
There are 12 ones in each row(in this example), all others are zero.
1 1 1 1 1 1 1 1 1 1 1 1 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 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 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 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
I need a code to generate this matrix appropriate for all i and s values.
Thanks for help!

Réponse acceptée

the cyclist
the cyclist le 13 Juil 2016
i = 3;
s = 12;
M = zeros(i,i*s);
for n = 1:i
M(n,(n-1)*s+1:n*s) = 1;
end
  1 commentaire
Taner Cokyasar
Taner Cokyasar le 13 Juil 2016
Thank you so much cyclist.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting 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