필터 지우기
필터 지우기

How to fix this issue in the graph??

조회 수: 1 (최근 30일)
Aswin Sandirakumaran
Aswin Sandirakumaran 2018년 6월 28일
답변: Ameer Hamza 2018년 6월 28일
Gv = graph({'s1' 's_1' 's2' 's_2' },{'s2' 's_2','s3' 's_3'});
Gv.Nodes.Service = {'s1','s2','s_1','s_2','s3','s_3'}';
Application = Gv.Nodes;
Gvsub = graph();
figure(3)
hold on
plot(Gvsub);
hold off
for i = 1:numnodes(Gv)
if isempty(Gvsub.Nodes)
H = addnode(Gvsub,Gv.Nodes.Service(i));
else
H = addnode(Gvsub,Gv.Nodes.Service(i));
end
Application(1,:) = []; % REMOVING THE USED ROW AFTER BEING USED
end
PROBLEM: MY H is getting replaced till the last loop, instead it should store the values which got from the previous loop.
DOUBT: Since i am adding nodes to the Gvsub. Why Gvsub doesnt display the nodes which was obtained? Gvsub if plotted gives me a blank graph. HOW TO FIX THIS ISSUE?
OUTPUT: H graph should contains all the nodes of Gv. But now it just contains the last value of the last loop which is s_3 . HOW TO FIX THIS ISSUE?

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 6월 28일
That is because you are adding nodes to Gvsub and saving it in H, the Gvsub variable does not change and in next iteration, it again adds one node and save it in H while Gvsub remain constant in all loop iterations. To fix this, change the code as follow
Gv = graph({'s1' 's_1' 's2' 's_2' },{'s2' 's_2','s3' 's_3'});
Gv.Nodes.Service = {'s1','s2','s_1','s_2','s3','s_3'}';
Application = Gv.Nodes;
Gvsub = graph();
figure(3)
hold on
plot(Gvsub);
hold off
H = Gvsub;
for i = 1:numnodes(Gv)
if isempty(Gvsub.Nodes)
H = addnode(H,Gv.Nodes.Service(i));
else
H = addnode(H,Gv.Nodes.Service(i));
end
Application(1,:) = []; % REMOVING THE USED ROW AFTER BEING USED
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by