0

就像标题已经说的那样,我正在尝试绘制一棵生成树。

但是,如果我尝试绘制图表,则会出现以下错误:

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', ...

附加信息:

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. 

用更少的观察尝试了同样的方法,它工作得非常好。错误的原因是什么,如何修复代码?

4

1 回答 1

1

本示例使用的关键函数pplot来自minspanMATLOG工具箱。下面的代码创建一个网络,然后绘制一个最小生成树( wiki )。

还使用 MATLOG 的一些支持函数(参见下面的代码)来创建示例(取自MATLOG文档)。

%% 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')

最小生成树

于 2018-10-24T16:50:36.437 回答