Get the elements of diagonal and antidiagonal for any m-by-n matrix - MATLAB Cody - MATLAB Central

Problem 859. Get the elements of diagonal and antidiagonal for any m-by-n matrix

Difficulty:Rate

In the problem Problem 858. Permute diagonal and antidiagonal created by Jean-Marie SAINTHILLIER the test suite is only based on squared m-by-m matrix .

In this problem you must submit a solution which returns the diagonal and anti-diagonal elements without using the DIAG function for any m-by-n matrix

Example:

If the input is a matrix 4*3

x =  [ 0     0     0
       1    48    17
       0     2    99
       14    0    3]

we expect 2 output vectors:

dg_elements = [0 48 99] % diagonal elements
antidg_elements = [14 2 17 ] % anti-diagonal elements

Note : You do not have to permute anything. Just return the elements.

Solution Stats

31.83% Correct | 68.17% Incorrect
Last Solution submitted on Mar 07, 2025

Problem Comments

Solution Comments

Show comments
Primes and Rough Numbers, Basic ideas
What is a rough number? What can they be used...
3
5

Problem Recent Solvers484

Suggested Problems

More from this Author30

Community Treasure Hunt

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

Start Hunting!
Go to top of page