esort.m

来自「经典通信系统仿真书籍《通信系统与 MATLAB (Proakis)》源代码」· M 代码 · 共 39 行

M
39
字号
function [s,ndx]=esort(p)
%ESORT	Sort complex continuous eigenvalues in descending order
%
%	S=ESORT(P) sorts the complex eigenvalues in the vector P in
%	descending order by real part.  The unstable eigenvalues will 
%	appear first.
%
%	[S,NDX] = ESORT(P) also returns the vector NDX containing the 
%	indexes used in the sort.
%
%	See also: DSORT and SORT.

%	Clay M. Thompson  7-12-90
%	Copyright (c) 1986-93 by the Mathworks, Inc.

error(nargchk(1,1,nargin));

[m,n] = size(p);
if m==1, p=p.'; [m,n] = size(p); end

[s,ndx] = sort( -real(p) );
for i=1:n, s(:,i) = p(ndx(:,i),i); end

% Work around sort bug -- Remove when new sort routine is released.
for i=1:n,
  k=1;
  while k<m,
    if (imag(s(k,i))~=0),
      if (imag(s(k,i))<0),
         s(k:k+1,i)=conj(s(k:k+1,i));
         swap = ndx(k,i); ndx(k,i)=ndx(k+1,i); ndx(k+1,i)=swap;
      end
      k = k+2;
    else
      k = k+1;
    end
  end
end

⌨️ 快捷键说明

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