matrix shift elements with specific way
Mostra commenti meno recenti
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??
Risposte (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,:)
Categorie
Scopri di più su Operating on Diagonal Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!