diagonal matrix with ones
136 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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:
if true
% code
a=[6,9,7;6,2,0;1,8,3]
a=tril(a)
end
1 Kommentar
Daniel Shub
am 8 Mär. 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.
Antworten (7)
Sean de Wolski
am 8 Mär. 2013
Bearbeitet: Sean de Wolski
am 8 Mär. 2013
eye(5)
?
more per clarification:
a = tril(magic(3));
a(logical(eye(size(a,1)))) = 1
0 Kommentare
Leah
am 8 Mär. 2013
a(eye(3))=1;
like that?
3 Kommentare
Sean de Wolski
am 8 Mär. 2013
I'm sure your friendly sales rep would be happy to set you up with a trial :) !
Miroslav Balda
am 9 Mär. 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)
0 Kommentare
Miroslav Balda
am 9 Mär. 2013
There is even simpler solutionof your problem:
Anew = diag(diag(A))\tril(A)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!