vsort.m
来自「经典通信系统仿真书籍《通信系统与 MATLAB (Proakis)》源代码」· M 代码 · 共 35 行
M
35 行
function [v2,pind]=vsort(v1,v2,sp)
% VSORT Matches two vectors. Used in RLOCUS.
% VS2 = VSORT(V1,V2) matches two complex vectors
% V1 and V2, returning VS2 with consists of the elements
% of V2 sorted so that they correspond to the elements
% in V1 in a least squares sense.
% [v2,pind]=VSORT(v1,v2,sp)
% sp is used to test a quick sort method and is equal to
% sp=sum([1:length(indr)].^2); pind=1 is returned if
% a slow sort method has to be applied.
% Copyright (c) 1986-93, by the MathWorks, Inc.
pind=0;
if nargin < 3, sp = sum([1:length(v1)].^2); end
% Quick Sort
p=length(v2);
vones=ones(p,1);
[dum,indr1]=min(abs(vones*v2.'-v1*vones'));
indr(indr1)=[1:p];
% Long (accurate) sort
if (indr*indr' ~= sp)
[dum,jnx]=sort(abs(v2));
pind=1;
for j=jnx'
[dum,inx]=min(abs(v2(j)-v1));
indr(inx)=j;
v1(inx)=1e30;
end
end
v2=v2(indr);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?