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