How would I make a script to find the Diagonal of a matrix?
조회 수: 3 (최근 30일)
이전 댓글 표시
I know you could simply use the Diag function but I am playing around with making scripts and I am curious.
댓글 수: 0
답변 (2개)
Star Strider
2018년 2월 11일
편집: Star Strider
2018년 2월 11일
Hi, Curious Alicia Gillies!
I would do this:
M = ...; % Your Matrix
for k = 1:min(size(M))
diagM(k) = M(k,k);
end
and to create a diagonal matrix from the same ‘diagM’ (or any other) vector:
N = eye(numel(diagM)) .* diagM(:);
댓글 수: 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!