diagonal matrix with ones
129 次查看(过去 30 天)
显示 更早的评论
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 个评论
Daniel Shub
2013-3-8
What would be really helpful is if in addition to your example input you could tell us what you want the output to be.
回答(7 个)
Sean de Wolski
2013-3-8
编辑:Sean de Wolski
2013-3-8
eye(5)
?
more per clarification:
a = tril(magic(3));
a(logical(eye(size(a,1)))) = 1
0 个评论
Leah
2013-3-8
a(eye(3))=1;
like that?
3 个评论
Sean de Wolski
2013-3-8
I'm sure your friendly sales rep would be happy to set you up with a trial :) !
Miroslav Balda
2013-3-9
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 个评论
Miroslav Balda
2013-3-9
There is even simpler solutionof your problem:
Anew = diag(diag(A))\tril(A)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!