www.gusucode.com > rctobsolete 工具箱 matlab源码程序 > rctobsolete/lmi/private/xdiag.m

    % Extracts the diagonal of a (not necessarily square) matrix
% Unlike DIAG, it properly behaves when M is 1xn or nx1

% Author: P. Gahinet  6/94
% Copyright 1995-2004 The MathWorks, Inc.

function d=xdiag(M)

if size(M,1)==1 | size(M,2)==1,
   d=M(1,1);
else
   d=diag(M);
end