I have a matrix, for example A=[ 1 0 0 0 ; 0 2 0 0 ; 0 0 3 0 ; 0 0 0 4]; I want to reference to the n th diagonal, for example the 2nd and 4th ones, that means [2,4]. Is there a elegant way to do this without using a loop. I tried using A([2,4],[2,4]) but it gave a 2*2 matrix. Anybody knows how to do this? Thanks.
MATLAB: Matlab to extract the n th diagonals in a Matrix
matrix reference
Related Question
- Finding the mean of a matrix row? Get error “Subscript indices must either be real positive integers or logicals.”
- How to get the secondary diagonal of a matrix
- How to Assemble the matrix shown in the image on Matlab for any number of nodes
- How to solve this problem? I want to make code to solve this problem. I made the matrix D using triu function in matlab and than D=t+t.’
- Matrix define using for loop
- Need help creating an array
Best Answer