Generate matrix with a pattern

조회 수: 3 (최근 30일)
Michael Henry
Michael Henry 2020년 12월 14일
편집: Michael Henry 2020년 12월 14일
Hello guys,
I need your help please. If I want to generate matrix given the rows and columns Cx(NXC) like this
where here, C = 3, N = 4.
The first row consists of three elements which is C then it repeats itself for 4 times which is N. The second row starts with 0 then the same pattern. It looks like diagonal matrices.
The most important thing is to be changeable according to any value of C and N but with the same pattern. Always N >C
Many thanks for your help!

채택된 답변

KSSV
KSSV 2020년 12월 14일
편집: KSSV 2020년 12월 14일
I = eye(3) ;
iwant = repmat(I,1,4)
iwant = 3×12
1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1
  댓글 수: 1
Michael Henry
Michael Henry 2020년 12월 14일
편집: Michael Henry 2020년 12월 14일
Thank you so much my friend KSSV. Can I ask you for one last favor please, how I can generate another matrix like this (4X12)
Where here the 3 ones are in first row then all zeros. The second row starts with 3 zeros then three ones then zeros to the end. This repates for all rows. But I need to generate such pattern for any number of rows and columns. For example, for (4X8), it should look like
Many thanks for your time!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by