each diagonal of a matrix
2 ビュー (過去 30 日間)
古いコメントを表示
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/188253/image.png)
i want sum diagonal matrix like this pic. please help me
0 件のコメント
採用された回答
Star Strider
2018 年 4 月 23 日
Try this:
A = [1 2 3; 4 5 6; 7 8 9];
Af = fliplr(A); % Flip Matrix
ND = size(A,1)-1; % Number of Diagonals
D = ND:-1:-ND; % Diagonal Offset Vector
for k = 1:numel(D)
Dsum(k) = sum(diag(Af,D(k))); % Sum Each Diagonal
end
2 件のコメント
その他の回答 (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!