Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: arrengment of eigenvalu and eigenvector
Date: Tue, 1 Jan 2008 10:52:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 48
Message-ID: <fld60k$lk3$1@fred.mathworks.com>
References: <flco7r$ieu$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.fr>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1199184724 22147 172.30.248.37 (1 Jan 2008 10:52:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 1 Jan 2008 10:52:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:443941


"mustafa alheety" <alheety@yahoo.com> wrote in message
<flco7r$ieu$1@fred.mathworks.com>...
> Dear all...
> Hello...
> 
> happy new year frist. please i want to ask if that 
> possible in matlab to give my the eigenvalue and eigen 
> vector arrengement decreasing

I have sone a small m-file for you.

Bruno

function [varargout]=seig(varargin)
% function [varargout]=seig(varargin);
% SEIG sorted Eigenvalues and eigenvectors.
% Calling: similar MATLAB builtin EIG with optional 
% last parameter can be 'ascend' or 'descend'
% for sorting purpose
%
% Related function eig and sort
%

vin=varargin;
sopt='';
% Look where as last argument is 'ascend' or 'descend'
if length(varargin)>=2 && ischar(varargin{end})
    sopt=lower(varargin{end});
    switch sopt
        case {'ascend' 'descend'}
            vin=varargin(1:end-1);
    end
end

nout=max(nargout,1);
varargout=cell(1,nout);
[varargout{:}]=eig(vin{:}); % call eig

if ~isempty(sopt)
    if nout==1 % Calling with 1 output
        varargout{1}=sort(varargout{1},sopt);
    else % Calling with 2 outputs
        [ds is]=sort(diag(varargout{2}),sopt);
        varargout{2}=diag(ds);
        varargout{1}=varargout{1}(:,is); % rearrange
eigen-vectors
    end
end