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 件)

Matt J
Matt J 2021 年 8 月 31 日
編集済み: Matt J 2021 年 8 月 31 日

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,:)
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

カテゴリ

ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索

質問済み:

2021 年 8 月 31 日

編集済み:

2021 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by