How do I change the topology of my nodes?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I want to connect the PSE with multiple PDs in a bus topology like this.
PSE----------------------------------------------------------------------
|| || ||
PD1 PD2 PD3
Any help would be great. Thanks!
This is my code :
% Create connection matrix
connections = zeros(num_nodes + 1);
% Connect each PD to the PSE from the left side
connections(1, 2) = 1;
connections(1, 3) = 1;
connections(1, 4) = 1;
% Create a digraph object
g = digraph(connections);
% Set the node properties
g.Nodes.Name = {'PSE'; 'PD1'; 'PD2'; 'PD3'};
g.Nodes.Type = {'PSE'; 'PD'; 'PD'; 'PD'};
% Define the node positions
nodePositions = [0, 0; 0, -1; 0, -2; 0, -3];
% Define custom markers for PSE and PDs
pseMarker = 's';
pdMarker = 's';
% Plot the graph with customized node markers and positions
figure;
h = plot(g, 'NodeColor', 'r', 'NodeLabel', '', 'MarkerSize', 10, ...
'XData', nodePositions(:, 1), 'YData', nodePositions(:, 2), 'ShowArrows', 'off');
% Customize the node markers
hold on;
for i = 1:num_nodes+1
if i == 1
marker = pseMarker;
else
marker = pdMarker;
end
plot(nodePositions(i, 1), nodePositions(i, 2), marker, 'MarkerSize', 20, 'MarkerFaceColor', 'r');
end
hold off;
% Adjust the axes limits
xLimits = [min(nodePositions(:, 1)) - 1, max(nodePositions(:, 1)) + 1];
yLimits = [min(nodePositions(:, 2)) - 1, max(nodePositions(:, 2)) + 1];
axis([xLimits, yLimits]);
% Add edge labels
edgeLabels = {'PD1'; 'PD2'; 'PD3'};
edgeIdx = find(connections(2:end, 1));
edgeX = nodePositions(edgeIdx, 1);
edgeY = nodePositions(edgeIdx, 2);
댓글 수: 0
답변 (1개)
Amit Dhakite
2023년 6월 7일
Hi Divya,
After analysing your code, I got to know that the "nodePositions" are forming a straight line.
If you want to arrange the nodes in a bus topology, you can change the "nodePositions" as described below:
% Define the number of nodes
num_nodes = 3;
% Create connection matrix
connections = zeros(num_nodes + 1);
% Connect each PD to the PSE from the left side
connections(1, 2) = 1;
connections(1, 3) = 1;
connections(1, 4) = 1;
% Create a digraph
g = digraph(connections);
% Define the node positions
nodePositions = [0, 0; -1, -1; 0, -1; 1, -1];
% Plot the graph with customized node markers and positions
figure;
h = plot(g, 'NodeColor', 'r', 'NodeLabel', '', 'MarkerSize', 10, ...
'XData', nodePositions(:, 1), 'YData', nodePositions(:, 2), 'ShowArrows', 'off');
If you want to represent multiple PSE nodes, then you can consider the following example:
% Create connection matrix
connections = zeros(6);
% Connect each PD to one of the PSE
connections(1, 4) = 1;
connections(2, 5) = 1;
connections(3, 6) = 1;
connections(1, 2) = 1;
connections(2, 3) = 1;
% Create a digraph
g = digraph(connections);
% Define the node positions
nodePositions = [-1, 0; 0, 0; 1, 0; -1, -1; 0, -1; 1, -1];
% Plot the graph with customized node markers and positions
figure;
h = plot(g, 'NodeColor', 'r', 'NodeLabel', '', 'MarkerSize', 10, ...
'XData', nodePositions(:, 1), 'YData', nodePositions(:, 2), 'ShowArrows', 'off');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!