필터 지우기
필터 지우기

How to create such a matrix like this?

조회 수: 1 (최근 30일)
Taner Cokyasar
Taner Cokyasar 2016년 7월 13일
댓글: Taner Cokyasar 2016년 7월 13일
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!

채택된 답변

the cyclist
the cyclist 2016년 7월 13일
i = 3;
s = 12;
M = zeros(i,i*s);
for n = 1:i
M(n,(n-1)*s+1:n*s) = 1;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by