[10] | 1 | %MSTPLOT Plot minimum spanning trees
|
---|
| 2 | %
|
---|
| 3 | % MSTPLOT (A,L)
|
---|
| 4 | %
|
---|
| 5 | % INPUT
|
---|
| 6 | % A Nx2 or Nx3 Data matrix
|
---|
| 7 | % L List of edges belonging to one or more minimum spanning trees
|
---|
| 8 | %
|
---|
| 9 | % DESCRIPTION
|
---|
| 10 | % Plots data and edges in the minimum spanning trees. Applicable only
|
---|
| 11 | % for 2D or 3D data. L can be found by KMST. If A is unknown, but
|
---|
| 12 | % dissimilarity data are given, then a 2D or 3D approximation can be
|
---|
| 13 | % found by PSEM.
|
---|
| 14 | %
|
---|
| 15 | % SEE ALSO
|
---|
| 16 | % KMST, PSEM
|
---|
| 17 |
|
---|
| 18 | % Copyright: Elzbieta Pekalska, ela.pekalska@googlemail.com
|
---|
| 19 | % Faculty EWI, Delft University of Technology and
|
---|
| 20 | % School of Computer Science, University of Manchester
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | function mstplot (A,L)
|
---|
| 24 | A = +A;
|
---|
| 25 | [n,m] = size(A);
|
---|
| 26 |
|
---|
| 27 | len = length(L);
|
---|
| 28 | K = round (len/(n-1));
|
---|
| 29 |
|
---|
| 30 | if m == 2,
|
---|
| 31 | plot(A(:,1),A(:,2),'.r')
|
---|
| 32 | text(A(:,1),A(:,2),num2str([1:n]'));
|
---|
| 33 | grid on;
|
---|
| 34 | hold on;
|
---|
| 35 | for i=1:len
|
---|
| 36 | plot([A(L(i,1),1) A(L(i,2),1)],[A(L(i,1),2) A(L(i,2),2)],'k');
|
---|
| 37 | end
|
---|
| 38 |
|
---|
| 39 | elseif m == 3,
|
---|
| 40 |
|
---|
| 41 | plot3(A(:,1),A(:,2),A(:,3),'.r')
|
---|
| 42 | text(A(:,1),A(:,2),A(:,3),num2str([1:n]'));
|
---|
| 43 | grid on;
|
---|
| 44 | hold on;
|
---|
| 45 | for i=1:len
|
---|
| 46 | plot3([A(L(i,1),1) A(L(i,2),1)],[A(L(i,1),2) A(L(i,2),2)],[A(L(i,1),3) A(L(i,2),3)],'k');
|
---|
| 47 | end
|
---|
| 48 | else
|
---|
| 49 | error('Plotting is only possible for two or three variables.');
|
---|
| 50 | return;
|
---|
| 51 | end
|
---|
| 52 |
|
---|
| 53 | hold off
|
---|
| 54 | if K == 1,
|
---|
| 55 | title('Minimum Spanning Tree');
|
---|
| 56 | else
|
---|
| 57 | title([num2str(K) ' Minimum Spanning Trees']);
|
---|
| 58 | end
|
---|
| 59 | return;
|
---|