function lambda = PHbarcode(C)
% function lambda = PHbarcode(C)
% 
% The function computes the sequence of filtration values lambda out of a given 
% connectivity matrix C using the Kruskal's algorithm for determining 
% the minimum spanning tree.
%
% lambda: filtration value
% Y     : 
%
% (C) 2012 Moo K. Chung
% mkchung@wisc.edu
% Department of Biostatistics and Medical Informatics
% University of Wisconsin-Madison
%
% Update: 2012 March 20 created
%         2017 December 18 function value added.

p=size(C,1);

G=sparse(C);
[Tree, pred] = graphminspantree(G, 'Method', 'Kruskal');

d=[];
for i=1:p
    for j=1:p
        if Tree(i,j)~=0
            d=[d Tree(i,j)];
        end
    end;
end

lambda=sort(d); 
lambda=full(lambda); %converts sparse matrix to full
p=length(lambda)

lambda = lambda + (1:p)/100000000;

