The well-known max function can operate along either the rows or the columns of a matrix by using

[Y,I] = max(X,[],1) or [Y,I] = max(X,[],2)

but it cannot operate along a diagonal dimension. For this problem, create a function that returns the largest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).

Example

If

X = magic(3) = [8 1 6
                3 5 7
                4 9 2]

then

Y = maxdiag(X) = [4 9 8 7 6]

See also mindiag.

Solution Stats

249 Solutions

66 Solvers

Last Solution submitted on Dec 10, 2025

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers66

Suggested Problems

More from this Author43

Community Treasure Hunt

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

Start Hunting!