📄 csort.m
字号:
function [cs,so]=csort(c,f)
%CSORT Sort columns into continuous vectors.
% CSORT(C) sorts the columns of C into
% continuous vectors by rearranging the columns
% one row at a time to minimize the differences
% between the rows.
%
% [CS,SO]=CSORT(C) also returns the sorting matrices
% in MVFR form such that
% CS=FMULF(W,C,SO) where length(W) = number of rows of C.
%
% [CS,SF]=CSORT(C,F) rearranges the columns of the component
% matrices of the MVFR matrix F in the same way as the
% columns of C are rearranged.
% This can be used to preserve the eigenvalue/eigenvector
% relationship while making the eigenvalues into
% continuous curves.
% See FEIG
% Dr M.P. Ford 4th August 1987
% Copyright (c) 1987 by GEC Engineering Research Centre & Cambridge Control Ltd
% MRN0019
ni=nargin;
no=nargout;
[m,n]=size(c);
if n==1
error('Cannot sort one column');
end
if m==1
error('Cannot sort one row');
end
if (ni==2)&(no~=2)
error('Inconsistent number of Input and Output arguments');
elseif ni==2 % must have 2 outputs
[mf,nf]=fsize(c(:,1),f);
if n~=nf
error('Columns of component matrices of F not equal to the columns of C');
end
so=f;
else % ie ni==1
if no==2
so=eyef(c(:,1),n);
f=so;
end % if no==2
end % if (ni==2)&(no~=2)
id=eye(n);
d=id;
infinity=ones(1,n)*2/eps; % Note +and- inf is always returned
% as the minimun from the MIN function
cs=c;
k=1:n;
for j=1:m-1
x=zeros(n);
for i=1:n
d(i,:)=abs(cs(j,:)-cs(j+1,i));
end % for i=1:n
for i=1:n
[dmin,di]=min(d);
[dmin,dj]=min(dmin);
x(di(dj),dj)=1;
d(di(dj),:)=infinity;
d(:,dj)=infinity';
end % for i=i:n
if any(any(x~=id)) % swap the columns below this point.
c(j+1:m,:)=cs(j+1:m,:);
for i=1:n
cs(j+1:m,i)=c(j+1:m,x(:,i));
end
if no==2 % only do this if required
f(1+j*n:m*n,:)=so(1+j*n:m*n,:);
for i=j:(m-1)
so(k+n*i,:)=f(k+n*i,:)*x;
end
end % if no==2
end % if any(any(x~=id))
end % for j=1:m-1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -