Azzera filtri
Azzera filtri

Need help with error on 'neighbors' function

1 visualizzazione (ultimi 30 giorni)
Shemin Sagaria
Shemin Sagaria il 20 Lug 2022
Commentato: Shemin Sagaria il 3 Ago 2022
Hi everyone,
I have a model developed in simulink with network connections. Each time the model has to analyse its neighbor nodes to progress. It is working fine during initial few seconds (upto 1000 sec), and I am facing error on 'neighbors' function after that (total runtime - 8760 sec). Each node have 2 neighbors.
s = [1 1 2 2 3 3 4 4]';
t = [2 3 1 4 1 4 2 3]';
v = [n1;n2;n3;n4]';
g = graph (s,t);
node = numel (v);
neg = find(v<0);
values_neg = v(neg);
ele = numel(neg);
z = zeros(1,node);
for k = 1:ele
for i = 1:node
if v(1,i)<0
a = neighbors(g, i);
b = v(a);
s = 0;
for j=1:connection
if b(j)>0
s = s+b(j);
end
end
z(1,i) = s+v(1,i);
else
z (1,i)= 0;
end
end
z';
zmin = min (z);
imin = find(z==zmin);
n = neighbors(g, imin);
vmin = v(imin);
[vmax, imax] = max(v(n));
borrowvalue = min(-vmin, vmax);
v(imin) = v(imin) + borrowvalue;
v(n(imax)) = v(n(imax)) - borrowvalue;
end
Error as follows:
Node ID must be a positive integer scalar not greater than the number of nodes in the graph (4). Error in 'four_Node/Subsystem/Energy management' (line 55) n = neighbors(g, imin);
Component: Simulink | Category: Model error
An error occurred while running the simulation and the simulation was terminated
Caused by:
  • Simulation stopped because of a runtime error.
I am using MATLAB 2021a. I hope some expericed member in the community can help me with this.
  5 Commenti
Christine Tobler
Christine Tobler il 2 Ago 2022
The error message is because the second input to neighbors is larger than the number of nodes in graph g. How is the graph g constructed? Does this change between time steps?
Possibly you need to make sure to use the constructor graph(s, t, numNodes) so that you have the correct number of nodes even if node 4 isn't connected to any edge.
Shemin Sagaria
Shemin Sagaria il 3 Ago 2022
Thank you. I will try this

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Specialized Power Systems in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by