From f953cd38829ca0992f133ab5349ae7ae37ad9214 Mon Sep 17 00:00:00 2001 From: Kevin D Date: Mon, 27 Oct 2025 19:52:10 -0700 Subject: [PATCH] added abstract network graph plot --- firstPlotSetup.m | 5 +++++ miSim.m | 22 +++++++++++++++++++++- test_miSim.m | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/firstPlotSetup.m b/firstPlotSetup.m index 96182a4..3b29be0 100644 --- a/firstPlotSetup.m +++ b/firstPlotSetup.m @@ -9,6 +9,7 @@ function f = firstPlotSetup(f) grid(f.Children(1).Children(1), "on"); view(f.Children(1).Children(1), 0, 90); xlabel(f.Children(1).Children(1), "X"); ylabel(f.Children(1).Children(1), "Y"); + title("Top-down Perspective"); % Communications graph nexttile(3, [1, 1]); @@ -16,8 +17,10 @@ function f = firstPlotSetup(f) axis(f.Children(1).Children(1), "image"); grid(f.Children(1).Children(1), "off"); view(f.Children(1).Children(1), 0, 0); + title("Network Graph"); % 3D view + title("3D Perspective"); nexttile(4, [2, 2]); axes(f.Children(1).Children(1)); axis(f.Children(1).Children(1), "image"); @@ -26,6 +29,7 @@ function f = firstPlotSetup(f) xlabel(f.Children(1).Children(1), "X"); ylabel(f.Children(1).Children(1), "Y"); zlabel(f.Children(1).Children(1), "Z"); % Side-on view + title("Side-on Perspective"); nexttile(6, [2, 1]); axes(f.Children(1).Children(1)); axis(f.Children(1).Children(1), "image"); @@ -34,6 +38,7 @@ function f = firstPlotSetup(f) ylabel(f.Children(1).Children(1), "Y"); zlabel(f.Children(1).Children(1), "Z"); % Front-on view + title("Front-on Perspective"); nexttile(10, [1, 2]); axes(f.Children(1).Children(1)); axis(f.Children(1).Children(1), "image"); diff --git a/miSim.m b/miSim.m index dd52399..c154bcf 100644 --- a/miSim.m +++ b/miSim.m @@ -59,7 +59,7 @@ classdef miSim end end - obj.adjacency = A; + obj.adjacency = A | A'; end function f = plotNetwork(obj, f) arguments (Input) @@ -97,6 +97,26 @@ classdef miSim copyobj(o, f.Children(1).Children(5)); end end + function f = plotGraph(obj, f) + arguments (Input) + obj (1, 1) {mustBeA(obj, 'miSim')}; + f (1, 1) {mustBeA(f, 'matlab.ui.Figure')} = figure; + end + arguments (Output) + f (1, 1) {mustBeA(f, 'matlab.ui.Figure')}; + end + + % Form graph from adjacency matrix + G = graph(obj.adjacency, 'omitselfloops'); + + % Check if this is a tiled layout figure + if strcmp(f.Children(1).Type, 'tiledlayout') + o = plot(f.Children(1).Children(4), G, 'LineStyle', '--', 'EdgeColor', 'g', 'NodeColor', 'k'); + else + o = plot(f.CurrentAxes, G, 'LineStyle', '--', 'EdgeColor', 'g', 'NodeColor', 'k'); + end + + end end methods (Access = private) diff --git a/test_miSim.m b/test_miSim.m index 4033729..71842d9 100644 --- a/test_miSim.m +++ b/test_miSim.m @@ -258,6 +258,9 @@ classdef test_miSim < matlab.unittest.TestCase % Plot communication links f = tc.testClass.plotNetwork(f); + + % Plot abstract network graph + f = tc.testClass.plotGraph(f); end end end \ No newline at end of file