필터 지우기
필터 지우기

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 CenterFile Exchange에서 Specialized Power Systems에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by