📄 diagproduct.m
字号:
function d = diagProduct(X, Y)% d = diagProduct(X, Y)%% Outputs the diagonal of the product of X and Y.% Faster than diag(X*Y).%% Inputs%% X matrix (m-by-n)% Y matrix (n-by-m)%% Output% d vector (m-by-1)[m,n] = size(X);[p,q] = size(Y);if m ~= q | n ~= p error('diagProduct: bad dimensions')end% P - a column vector of the rows of XP = X';P = P(:);% Q - a column vector of the columns of YQ = Y(:);% Z - an [n,m] matrix containing the components of P.*QZ = zeros(n,m);Z(:) = P .* Q;% d - the answer is the sum of the columns of Zd = colSum(Z)';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -