help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need to extract main diagonal to vector


From: Nicholas Jankowski
Subject: Re: Need to extract main diagonal to vector
Date: Thu, 9 Jul 2020 12:11:11 -0400

On Thu, Jul 9, 2020 at 12:07 PM Samuel Doughty <sdoughty11@gmail.com> wrote:
Is there an easy way to extract the elements of the main diagonal to a vector? This would basically be the inverse of the diag(x) operation.

According to the help for diag ('help diag' or https://octave.sourceforge.io/communications/function/diag.html), it does both functions. 

>> A = rand(1,3)
A =

   0.87334   0.41651   0.69806

>> diag(A)
ans =

Diagonal Matrix

   0.87334         0         0
         0   0.41651         0
         0         0   0.69806

>> diag(ans)
ans =

   0.87334
   0.41651
   0.69806


reply via email to

[Prev in Thread] Current Thread [Next in Thread]