function [P1,V,Pmat] = Recur_analysis(CC,method,sigma2);

PLT = 1;
if nargin == 1,
    method == 20;
    sigma2 = 1;
elseif nargin == 2;
    sigma2 = 1;
end

if method == 20 | method == 21,
    %Similarity Matrix
    Smat = simm(CC);
    %Smat = CC'*CC;
elseif method == 10 | method == 11,
    Smat = diag(ones(1,size(CC,2)));
    for i = 1:size(CC,2),
        for j = 1:i-1,
            Smat(i,j) = exp(-distispf(CC(:,i)',CC(:,j)')/sigma2);
            Smat(j,i) = Smat(i,j);
        end
    end
end


% Normalization by "node degree"
Zinv = diag(1./sum(Smat));
Pmat = Smat*Zinv;
[V,D] = eig(Pmat);

% This can be more efficiently estimated using the SVD "trick"
%invsqrtSmat = diag(1./sqrt(sum(Smat)));
%CCn = CC * invsqrtSmat;
%[U,L,V] = svd(CCn);

P1 = V(:,1);
P1 = P1/sum(P1);

if PLT,

    figure
    imagesc(Smat)
    title('Similarity Matrix')

    figure
    imagesc(Pmat)
    title('Markov matrix')

end