source: distools/plotgraph.m @ 40

Last change on this file since 40 was 10, checked in by bduin, 14 years ago
File size: 1.4 KB
Line 
1%PLOTGRAPH Plot a 2D graph
2%
3%   PLOTGRAPH (A,L,S)
4%
5% INPUT
6%   A   Nx2 or Nx3 Data matrix
7%   L   List of edges belonging to the graph
8%   S   Plotstring, default 'k'
9%
10% DESCRIPTION
11% Plots data and edges of a graph. Applicable only for 2D or 3D data.
12% If A is unknown, but dissimilarity data are given, then a 2D or 3D
13% approximation can be found by PSEM.
14%
15% SEE ALSO
16% KMST, PSEM, DISTGRAPH, GRAPHPATH
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 plotgraph (A,L,S)
24
25if narg < 3, S = 'k'; end
26A = +A;
27[n,m] = size(A);
28
29len = length(L);
30K   = round (len/(n-1));
31
32if m == 2,
33  plot(A(:,1),A(:,2),'.r')
34  text(A(:,1),A(:,2),num2str([1:n]'));
35  grid on;
36  hold on;
37  for i=1:len
38    plot([A(L(i,1),1) A(L(i,2),1)],[A(L(i,1),2) A(L(i,2),2)],S);
39  end
40
41elseif m == 3,
42
43  plot3(A(:,1),A(:,2),A(:,3),'.r')
44  text(A(:,1),A(:,2),A(:,3),num2str([1:n]'));
45  grid on;
46  hold on;
47  for i=1:len
48    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)],S);
49  end
50else
51  error('Plotting is only possible for two or three variables.');
52  return;
53end
54
55hold off
56if K == 1,
57  title('Minimum Spanning Tree');
58else
59  title([num2str(K) ' Minimum Spanning Trees']);
60end
61return;
Note: See TracBrowser for help on using the repository browser.