[10] | 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 |
|
---|
| 23 | function plotgraph (A,L,S)
|
---|
| 24 |
|
---|
[112] | 25 | if nargin < 3, S = 'k'; end
|
---|
[10] | 26 | A = +A;
|
---|
| 27 | [n,m] = size(A);
|
---|
| 28 |
|
---|
| 29 | len = length(L);
|
---|
| 30 | K = round (len/(n-1));
|
---|
| 31 |
|
---|
| 32 | if 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 |
|
---|
| 41 | elseif 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
|
---|
| 50 | else
|
---|
| 51 | error('Plotting is only possible for two or three variables.');
|
---|
| 52 | return;
|
---|
| 53 | end
|
---|
| 54 |
|
---|
| 55 | hold off
|
---|
| 56 | if K == 1,
|
---|
| 57 | title('Minimum Spanning Tree');
|
---|
| 58 | else
|
---|
| 59 | title([num2str(K) ' Minimum Spanning Trees']);
|
---|
| 60 | end
|
---|
| 61 | return;
|
---|