フィルターのクリア

Need help with error on 'neighbors' function

1 回表示 (過去 30 日間)
Shemin Sagaria
Shemin Sagaria 2022 年 7 月 20 日
コメント済み: Shemin Sagaria 2022 年 8 月 3 日
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 件のコメント
Christine Tobler
Christine Tobler 2022 年 8 月 2 日
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 2022 年 8 月 3 日
Thank you. I will try this

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecialized Power Systems についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by