How would I make a script to find the Diagonal of a matrix?
2 ビュー (過去 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!