Matlab identity shift matrix

前端 未结 6 1257
长发绾君心
长发绾君心 2020-12-17 18:38

Is there any inline command to generate shifted identity matrix in MATLAB?

A=[ ...
0, 1, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 1, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 1, 0, 0         


        
6条回答
  •  被撕碎了的回忆
    2020-12-17 19:30

    You can use circshift and fix the matrix before passing it to the function:

    >> shift = 1;
    >> N=10;
    >> A=circshift(diag(1:N>shift),-shift)
    A =
         0     1     0     0     0     0     0     0     0     0
         0     0     1     0     0     0     0     0     0     0
         0     0     0     1     0     0     0     0     0     0
         0     0     0     0     1     0     0     0     0     0
         0     0     0     0     0     1     0     0     0     0
         0     0     0     0     0     0     1     0     0     0
         0     0     0     0     0     0     0     1     0     0
         0     0     0     0     0     0     0     0     1     0
         0     0     0     0     0     0     0     0     0     1
         0     0     0     0     0     0     0     0     0     0
    

    1:N>shift will be 0 for fist shift number of places and 1 for the remaining.

提交回复
热议问题