diagonal matrix with ones
이전 댓글 표시
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
Leah
2013년 3월 8일
a(eye(3))=1;
like that?
댓글 수: 3
Sean de Wolski
2013년 3월 8일
You need the logical() around eye() or it will error.
Leah
2013년 3월 8일
thanks Sean, I'm waiting on my license at my new job :)
Sean de Wolski
2013년 3월 8일
I'm sure your friendly sales rep would be happy to set you up with a trial :) !
Cristian
2013년 3월 8일
0 개 추천
댓글 수: 2
Sean de Wolski
2013년 3월 8일
See my more section. Where'd the 1/3 and the 8/3 come from?
n=size(a,1);
a(1:n+1:end)=1;
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)
Miroslav Balda
2013년 3월 9일
There is even simpler solutionof your problem:
Anew = diag(diag(A))\tril(A)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!