diagsum.m

来自「统计分析的软件包」· M 代码 · 共 17 行

M
17
字号
function out=diagsum(X)
%DIAGSUM Sum of diagonals of a matrix.
%	DIAGSUM(A) is a row vector containing the sums of the diagonals
%	of the matrix A, from lower left to upper right.

% From makra@athena.mit.edu (Mohamad A. Akra)
% Massachusetts Institute of Technology
% Posted to comp.soft-sys.matlab, 29 July 93

[M,N] = size(X);
if M == 1,
   out = X;
else
   Y = [X zeros(M,M-2)].';
   out = sum( reshape( [zeros(M-1,1); Y(:); 0], M+N-1, M ).');
end;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?