Clear Filters
Clear Filters

How to create such a matrix like this?

1 view (last 30 days)
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!

Accepted Answer

the cyclist
the cyclist on 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

More Answers (0)

Categories

Find more on Shifting and Sorting 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!