about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/sort_evec.m
blob: e934aa56913bd128d99e46f01da3565b71944451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function [evec, evals] = sort_evec(temp_evec, temp_evals, N)

if ~isvectorBNT(temp_evals)
  temp_evals = diag(temp_evals);
end

% Eigenvalues nearly always returned in descending order, but just
% to make sure.....
[evals perm] = sort(-temp_evals);
evals = -evals(1:N);
if evals == temp_evals(1:N)
  % Originals were in order
  evec = temp_evec(:, 1:N);
  return
else
  fprintf('sorting evec\n');
  % Need to reorder the eigenvectors
  for i=1:N
    evec(:,i) = temp_evec(:,perm(i));
  end
end