-1

I need to extract the elements of the main diagonal of the matrix:

I have tried the following solution:

[U S V]= svd (T)
lambda= reshape(S',[],1);

But I have got the column vector with all elements but I need only the elements of the main diagonal

I also have tried:

[U S V]= svd (T)
lambda = diag(S);

But It doesn't"t work

Can someone help me to extract the elements of the diagonal?

1 Answers1

1

You should just be able to use diag directly on S

lambda = diag(S);

From the docs:

D = diag(v) returns a square diagonal matrix with the elements of vector v on the main diagonal.

Wolfie
  • 27,562
  • 7
  • 28
  • 55
  • if I write diag (T), I get the diagonal element of the T. But I need the diagonal element of the S matrix from svd of T – Noel Miller Aug 29 '19 at 09:39
  • I need to extract only the elements of the ain diagonal of the matrix – Noel Miller Aug 29 '19 at 09:40
  • 1
    @Noel then you need to edit your question to include a [mcve], because "it doesn't work" is not a clear enough problem statement, `lambda = diag(S)` will return the diagonal elements of `S`. – Wolfie Aug 29 '19 at 09:44