Error in ploting the network graph?how to make the code run??

n=10;
L=5;
B=4;
A=[L B];
% non-overlap distance > 5
distinct_BOUND = 2;
Z = zeros(n,2);
T = rand(1,2).*A;
Z(1,:) = T;
for i = 2:n
T = rand(1,2).*A;
for j = 1:i-1
while pdist([T;Z(j,:)],'euclidean') < distinct_BOUND
T = rand(1,2).*A;
end
end
Z(i,:) = T;
end
z=round(Z);
x=z(:,1);
y=z(:,2);
d=zeros(n,n-1);
% here we set the transmitting range tr=4
tr=4;
for i=1:n
for j=(i+1):n
Xi=x(i,:);
Yi=y(i,:);
Xj=x(j,:);
Yj=y(j,:);
X = [Xi,Yi;Xj,Yj];
d(i,j) =round( pdist(X,'euclidean'));
end
end
N=round((n*n-1)/2)
s=zeros(1,N);
t=zeros(1,N);
weights=zeros(1,N);
for i=1:n
for j=(i+1):n
if d(i,j)<tr
k=1;
D(1,k)=d(i,j);
s(1,k)=i;
t(1,k)=j;
end
k=k+1;
end
end
G = graph(s,t,weights)
figure(3)
plot(G)

5 件のコメント

Walter Roberson
Walter Roberson 2017 年 4 月 10 日
What error message do you observe?
Sneha Kolapalli
Sneha Kolapalli 2017 年 4 月 10 日
Error in matlab.internal.graph.constructFromEdgeList (line 125)
G = underlyingCtor(double(s), double(t), totalNodes);
Error in graph (line 260) matlab.internal.graph.constructFromEdgeList(...
Error in project1 (line 59) G = graph(s,t,weights)
Christine Tobler
Christine Tobler 2017 年 4 月 10 日
編集済み: Christine Tobler 2017 年 4 月 10 日
It looks like you left out the first line of the error message, containing the actual message. I think the error message you were likely to get here, would be:
Error using matlab.internal.graph.MLGraph
Source must be a dense double array of positive integer node indices.
I'd expect the problem to be that your vectors s and t contain zeros, but they are required to only contain indexes >= 1.
Sneha Kolapalli
Sneha Kolapalli 2017 年 4 月 11 日
yes.But how do I remove those zero values from the s,t ,weights.
Walter Roberson
Walter Roberson 2017 年 4 月 12 日
Do you want the 0s to indicate there is no connection?

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNetworks についてさらに検索

質問済み:

2017 年 4 月 10 日

コメント済み:

2017 年 4 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by