0

I am trying to plot, like the title already says, a spanning tree.

But I am getting following error if I try to plot my graph:

Error using rng
Too many input arguments.

Error in matlab.internal.graph.MLGraph/forceLayout>layoutOneConnComp (line 82)
    oldstate = rng(0,'twister');

Error in matlab.internal.graph.MLGraph/forceLayout (line 55)
        [x,y] = layoutOneConnComp(x,y,sources,targets,iterations);

Error in matlab.graphics.chart.primitive.GraphPlot/layoutforce

Error in matlab.graphics.chart.primitive.GraphPlot/layout>layoutauto

Error in matlab.graphics.chart.primitive.GraphPlot/layout

Error in matlab.graphics.chart.primitive.GraphPlot

Error in graph/plot (line 110)
hObj = matlab.graphics.chart.primitive.GraphPlot('BasicGraph', ...

Additional Information:

GrangerLandN={ 'X' 'Y' 'Z' ...}';
GrangerCoal={ 'A' 'B' 'C' ...}'; 
GrangerValues=(1,2,3,...)'; 

GG=graph(GrangerLandN,GrangerCoal,GrangerValues)

GG = 

  graph with properties:

    Edges: [100×2 table]
    Nodes: [20×1 table]

plot(GG) %also tried plot(GG,'EgdesLabel',GG.Edges.Weight) but both are throwing the error stated above. 

Tried the same with less observations and it worked perfectly fine. What is the reason for the error, and how can I fix the code?

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
CMW
  • 1
  • 1
  • "Error using rng Too many input arguments." This sounds like you've overwritten (shadowed) the default `rng` function. If `which rng` does not return `/toolbox/matlab/randfun/rng.m` then you need to delete (or rename) the file indicated there. – Cris Luengo Oct 24 '18 at 20:05

1 Answers1

1

The key functions used for this example are pplot and minspan from the MATLOG toolbox. The code below creates a network and then plots a minimum spanning tree (wiki).

Some supporting functions from MATLOG are also used (see code below) to create the example (taken from MATLOG documentation).

%% 2. Create Delaunay Network from Cities Centered around Atlanta
%% Make network using cities of 30k pop. within 150 miles of Atlanta
Atl = uscity('XY',mand({'Atlanta'},uscity('Name'),{'GA'},uscity('ST')));
[Name,XY]=uscity10k('Name','XY', ...
   (dists(Atl,uscity10k('XY'),'mi') < 150)' & uscity10k('Pop') > 30000);
makemap(XY)
pplot(XY,'r.')

%% Use Delaunay triangulation as road network
tri = delaunay(XY(:,1),XY(:,2));  % Delaunay triangulation
IJ = tri2list(tri);  % Convert to arc list
d = diag(dists(XY(IJ(:,1),:),XY(abs(IJ(:,2)),:),'mi'));
d = d * 1.2;  % Convert great circle to estimated road distances
d = round(d);
IJD = [IJ d];
pplot(IJD,XY,'m-')
pplot(IJD,num2cellstr(d),XY)

%% Minimum Spanning Tree (Kruskal algorithm)
t = minspan(IJD);
pplot(IJD(t~=0,:),XY,'b-','LineWidth',2,'DisplayName','minspan')

Minimum Spanning Tree

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
  • @CrisLuengo, two reasons. (1) OP asked this 10 months ago...my answer is for future seekers more than for OP. (2) this is they way I knew how to do it and I believe aspects of `pplot` or components may help OP. Would you prefer me to delete my answer? – SecretAgentMan Oct 25 '18 at 03:54
  • No, not at all. I would have downvoted it if I thought it was useless. It is actually quite a good answer, it just does't directly answer this question. :) – Cris Luengo Oct 25 '18 at 04:16
  • I honestly just didn't know how to directly answer it using the OP's approach but I knew how to do it with this. I appreciate the feedback. – SecretAgentMan Oct 25 '18 at 13:01