Flip the main diagonal of a matrix - MATLAB Cody - MATLAB Central

Problem 545. Flip the main diagonal of a matrix

Difficulty:Rate

Given a n x n matrix, M, flip its main diagonal.

Example:

 >> M=magic(5);
 >> flipDiagonal(M)
     9    24     1     8    15
    23    21     7    14    16
     4     6    13    20    22
    10    12    19     5     3
    11    18    25     2    17

Solution Stats

41.99% Correct | 58.01% Incorrect
Last Solution submitted on Jun 26, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
2
3

Problem Recent Solvers848

Suggested Problems

More from this Author16

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!