matrix shift elements with specific way
Afficher commentaires plus anciens
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)
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,:)
Catégories
En savoir plus sur Operating on Diagonal Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!