diagonal matrix with ones
127 views (last 30 days)
Show older comments
Hello I am trying to do a diagonal inferior matrix with a diagonal of ones but my diagonal have differentes valors. How do i do a matrix with diagonal of ones? Here is my code:
Daniel Shub on 8 Mar 2013
What would be really helpful is if in addition to your example input you could tell us what you want the output to be.
Edited: Sean de Wolski on 8 Mar 2013
more per clarification:
a = tril(magic(3));
a(logical(eye(size(a,1)))) = 1
Leah on 8 Mar 2013
I'm sure your friendly sales rep would be happy to set you up with a trial :) !
Matt J on 8 Mar 2013
Edited: Matt J on 8 Mar 2013
Your last comment explained how to construct the resulting matrix. You see, how important it is to precisely formulate your question.
Anew = diag(1./diag(A))'*tril(A)
There is even simpler solutionof your problem:
Anew = diag(diag(A))\tril(A)
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!