Filter löschen
Filter löschen

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?

1 Ansicht (letzte 30 Tage)
%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 Kommentar
Sneha Kolapalli
Sneha Kolapalli am 11 Apr. 2017
Bearbeitet: Sneha Kolapalli am 11 Apr. 2017
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 12 Apr. 2017
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)

Kategorien

Mehr zu Networks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by