Hello,
i want to create a matrix n*m like this
1 -1 0 0 0 0....0 0
-1 1 0 0 0 0....0 0
0 1 -1 0 0 0....0 0
0 -1 1 0 0 0....0 0
.....
0 0 0 0 0 0.....1 -1
0 0 0 0 0 0.....-1 1
Should i make a zeros matrix first, and then fill the first two rows and shift them??

Réponses (1)

Matt J
Matt J le 31 Août 2021
Modifié(e) : Matt J le 31 Août 2021
One way:
N=4; %number of shifted blocks
A=repelem(eye(N+2),2,1);
A=diff(A,1,2);
A([1,2,end-1,end],:)=[];
A(2:2:end,:)=-A(2:2:end,:)
A = 8×5
1 -1 0 0 0 -1 1 0 0 0 0 1 -1 0 0 0 -1 1 0 0 0 0 1 -1 0 0 0 -1 1 0 0 0 0 1 -1 0 0 0 -1 1

Catégories

Question posée :

le 31 Août 2021

Modifié(e) :

le 31 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by