CLC
Clear all;
Close all;
Distance = [0,2,4,6,6,8;
2,0,4,6,6,8;
4,4,0,6,6,8;
6,6,6,0,4,8;
6,6,6,4,0,8;
8,8,8,8,8,0];
S = [' A ', ' B ', ' C ', ' D ', ' E ', ' F '];
L = Length (Distance (:, 1));
r= [];
Sresult = [];
Stemp = [];
Percent of NJ algorithm
While L > 2
%calculate R (i) =sum (d (i,k))/(L-2);
r = [];
For i = 1:l
R = [R;sum (Distance (:, I))/(L-2)];
End
%calculate d (i) = d (i,j)-R (i)-R (J);
For I =1:l
for J =1:l
if i = = J
Distancetemp (I,J) = 0;
Else
Distancetemp (i,j) = Distance (i,j)-R (i)-R (J);
End
End
End
%find min weight
minweight = min (min (distancetemp));
[Row,con] = find (distancetemp = = minweight);
row = row (1);
con = con (1);
Stemp = strcat (S (min (Row,con)), S (Max (Row,con)));
Sresult = [Sresult,stemp]
S (row) = [];
S (Con) = [];
S = strcat (s,stemp);
%update Distance
Combinevector = (Distance (row,[1:min (Row,con) -1,min (Row,con) +1:max (Row,con)-1,...
Max (Row,con) +1:l]) + Distance (con,[1:min (Row,con) -1,min (Row,con) +1:max (Row,con)-1,...
Max (Row,con) +1:l])-Distance (Row,con))/2;
Distance = Distance ([1:min (Row,con) -1,min (Row,con) +1:max (Row,con)-1,...
Max (Row,con) +1:l],[1:min (Row,con) -1,min (Row,con) +1:max (Row,con)-1,...
Max (Row,con) +1:l]);
L = Length (Distance (:, 1));
Distance (l+1,1:l) = Combinevector;
Distance (1:l,l+1) = Combinevector ';
Distance (l+1,l+1) = 0;
L = l + 1;
End
Neighbour-joining (NJ algorithm)