matrix shift elements with specific way
显示 更早的评论
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??
回答(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,:)
类别
在 帮助中心 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!