フィルターのクリア

1.How to get (s,t, weights) to generate a graph? The way i used to generate them causes graph error?2.2.Is it possible keep a for loop inside the if statement to take k values only for d(i,j)<tr ,if how to write the statement?

2 ビュー (過去 30 日間)
%n=number of nodes and d(i,j)is the distance between all nodes should be less than transmitting range tr(to establish connection between nodes)
N=round((n*n-1)/2)
s=zeros(1,N);
t=zeros(1,N);
weights=zeros(1,N);
k=1;
for i=1:n
for j=(i+1):n
if d(i,j)<tr
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)
plot(G)
  1 件のコメント
Sneha Kolapalli
Sneha Kolapalli 2017 年 4 月 11 日
編集済み: Sneha Kolapalli 2017 年 4 月 11 日
1.Error using matlab.internal.graph.MLGraph Source must be a dense double array of node indices.
Error in matlab.internal.graph.constructFromEdgeList (line 125) G = underlyingCtor(s, t, totalNodes);
Error in graph (line 264) matlab.internal.graph.constructFromEdgeList(...
2.Is it possible keep a for loop inside the if statement to take k values only for d(i,j)<tr ,if how to write the statement.

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

回答 (1 件)

Steven Lord
Steven Lord 2017 年 4 月 12 日
As Christine Tobler commented in this post, I suspect your s and/or t inputs to graph contain one or more 0 elements. Try trimming the excess points that you didn't fill with data after your loop.
% Fill in part of a vector
% This is a "toy" example; there are better ways to create the final x vector
x = zeros(1, 10);
k = 1;
for z = 1:7
x(k) = z;
k = k+1;
end
disp(x)
% Trim unused elements
x(k:end) = [];
disp(x)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by