How can i create this specific matrix??

1 view (last 30 days)
Hello. I'm MATLAB beginner.
I want to make A matrix like below.
ex1)
i = 2
j = 3
A = [1,1,0,0,0,0 ; 0,0,1,1,0,0 ; 0,0,0,0,1,1]
ex2)
i = 2
j = 2
A = [1,1,0,0 ; 0,0,1,1]
ex3)
i = 3
j = 4
A = [1,1,1,0,0,0,0,0,0,0,0,0 ; 0,0,0,1,1,1,0,0,0,0,0,0 ; 0,0,0,0,0,0,1,1,1,0,0,0 ; 0,0,0,0,0,0,0,0,0,1,1,1]
Could you MATLAB masters please help me??

Accepted Answer

Chunru
Chunru on 9 Sep 2021
i=3;
j=4;
A = kron(eye(j), ones(1,i))
A = 4×12
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
  1 Comment
연승 김
연승 김 on 9 Sep 2021
wow. it works well!!
you are genius..!!!
Funcicton 'kron' is good^^

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating 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!