What is the function for receiving a vector that will contain the elements of the second diagonal?

I know that the function for the main diagonal is diag. Is there a function for the second diagonal? If not, how can I find it?

Answers (2)

Read the input description; there's a second optional argument to diag
From the documentation for diag: "x = diag(A,k) returns a column vector of the elements on the kth diagonal of A." and "k=0 represents the main diagonal, k>0 is above the main diagonal, and k<0 is below the main diagonal."
The second example on that documentation page shows how to use that syntax.

This question is closed.

Asked:

on 5 Apr 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!