How to create a 3 diagonal matrix with blocks

1 次查看(过去 30 天)
I would like to create a matrix of the following form, ideally without having to use a loop as its size can become rather large:
basically it is an 2N x 2N matrix with a double wide 3 diagonal.
If anyone can provide some assistance in this it would be much appreciated.

采纳的回答

Voss
Voss 2022-6-26
编辑:Voss 2022-6-26
N = 7;
M = zeros(2*N,N+2);
M( 1+(2*N+2)*(0:N-1) + reshape([0 1]+[0;1;2]*2*N,[],1) ) = 1;
disp(M);
1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by