Iterate over diagonal elements of a Matrix in MatLab
问题 I need to get the indexes of all diagonals in a matrix. The matrix can be non square. The diag function gives the values, but I need the coords. So for instance with this: [1 2 3; 4 5 6; 7 8 9] , I want [1 1; 2 2; 3;3] PLUS [2 6] and 3 because they are the upper diagonals of the matrix, and same for below i.e. [4 8] and 7 . So the full list of indexes is: [1 1; 2 2; 3 3], [1 2; 2 3], [1 3], [2 1], [3 2], [3 1] . And I need this in the other diagonal direction too... And it needs to work for