source: distools/mstplot.m @ 89

Last change on this file since 89 was 10, checked in by bduin, 14 years ago
File size: 1.3 KB
RevLine 
[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
23function mstplot (A,L)
24A = +A;
25[n,m] = size(A);
26
27len = length(L);
28K   = round (len/(n-1));
29
30if 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
39elseif 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
48else
49  error('Plotting is only possible for two or three variables.');
50  return;
51end
52
53hold off
54if K == 1,
55  title('Minimum Spanning Tree');
56else
57  title([num2str(K) ' Minimum Spanning Trees']);
58end
59return;
Note: See TracBrowser for help on using the repository browser.