How to calculate diagonal for NxN matrix ?
Mostrar comentarios más antiguos
Hi
I'm trying to calculate the sum diagonal from a square matrix (size NxN). For example: A = [1 2 3 4; 5 6 7 8; 9 0 1 2; 3 4 5 6]; %square matrix Then if you would rotate the matrix by 45 degrees and take sum of the rotated martix. Like: imrotate(A,45)
What I'm trying to do is to find the diagonal sum of A. Therefore I want to construct a vector of size 1x(N+2) or for this A = [1 2 3 4; 5 6 7 8; 9 0 1 2; 3 4 5 6] it would be an vector of size 1x6.
Could you please help me? :)
4 comentarios
Azzi Abdelmalek
el 18 de Sept. de 2012
what do you mean rotate 45°
Lily
el 18 de Sept. de 2012
Jan
el 18 de Sept. de 2012
Do you mean 90 deg instead of 45 deg?
Honglei Chen
el 18 de Sept. de 2012
I don't quite get it. Are you saying you want the sum along each diagonal? But if so, why is the resulting vector 1x(N+2)? Shouldn't it be 1x(2*N-1)? Could you post the desired answer for your sample matrix?
Respuesta aceptada
Más respuestas (1)
Wayne King
el 18 de Sept. de 2012
Editada: Wayne King
el 18 de Sept. de 2012
Just use trace()
trace(A)
2 comentarios
Lily
el 18 de Sept. de 2012
Wayne King
el 18 de Sept. de 2012
It's easy to say in general what an NxN matrix looks like for a multiple of 90 degrees, but what does it look like for 45? For N>3, I'm not sure what that looks like without padding the matrix with zeros like imrotate
Categorías
Más información sobre Operating on Diagonal Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!