Matlab identity shift matrix

前端 未结 6 1249
长发绾君心
长发绾君心 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:27

    Here is Another Alternative: (little similar to bsxfun Approach by Divakar)

    n=10;
    shift = 1;
    c = repmat(1-shift:n-shift,n,1,1);
    r = repmat((1:n).',1,n,1);
    out = r == c
    

    This could also be a one-liner:

    out = repmat((1:n).',1,n,1) == repmat(1-shift:n-shift,n,1,1)
    

提交回复
热议问题