Filter löschen
Filter löschen

How to create such a matrix like this?

1 Ansicht (letzte 30 Tage)
Taner Cokyasar
Taner Cokyasar am 13 Jul. 2016
Kommentiert: Taner Cokyasar am 13 Jul. 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!

Akzeptierte Antwort

the cyclist
the cyclist am 13 Jul. 2016
i = 3;
s = 12;
M = zeros(i,i*s);
for n = 1:i
M(n,(n-1)*s+1:n*s) = 1;
end

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting 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