Branch removal cause error in plotting graph with coordinates

조회 수: 2 (최근 30일)
Mohsen Mazidi
Mohsen Mazidi 2021년 7월 29일
답변: Devyani Maladkar 2021년 8월 25일
Hi
I have a graph of 124 edges and 125 vertices, then I remove some branches randomly:
b=branch;
idx=randperm(length(branch),40);
b(idx,:)=[];
then when I want to plot the graph:
p=position;
node=p(:,1);
x=p(:,2);
y=p(:,3);
G=graph(b(:,1)',b(:,2)',b(:,3)');
plot(G,'XData',x,'YData',y,'EdgeLabel',G.Edges.Weight,'NodeLabel',node)
I got the following error:
Expected XData to be an array with number of elements equal to 124.
I know its because graph function reduces number of nodes, but I don't want to, my node coordinates are fixed. Please would anyone give me some help?

답변 (1개)

Devyani Maladkar
Devyani Maladkar 2021년 8월 25일
Hello,
I understand from your question that you are plotting a graph and want to remove some branches randomly. Since you have a fixed number of nodes and node coordinates you don't want to remove the nodes, which results in the error.
Since you have fixed node coordinates, you can specify beforehand the total number of nodes. This can be done by specifying when graph object is created as below:
G=graph(b(:,1)',b(:,2)',b(:,3)',total_nodes);
The extra nodes are disconnected from the primary connected component.
For more information on creating the graph object using the above argument you can refer to the documentation under the section Edge List Construction with Extra Nodes. The documentation link refers to R2021a release but will work for R2015b release as well.
If you would like to refer to archived documentation, you can access it from the following link: https://www.mathworks.com/help/doc-archives.html .
For access to earlier releases, please contact support.

카테고리

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

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by