Create and plot an oriented graph of a circuit from a netlist (2024)

43 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

jf am 13 Aug. 2024 um 9:16

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist

Kommentiert: jf am 13 Aug. 2024 um 15:48

Akzeptierte Antwort: Steven Lord

In MATLAB Online öffnen

Hello,

it should be a ridiculously trivial task, but I have to admit I've been stuck on it for a few months. Sadly, I'm not very good at Python either, so I'm coming here.

Assume that I have some circuit like the one below:Create and plot an oriented graph of a circuit from a netlist (2)

I want to read and parse a netlist such that I create a digraph object, which can later be used for testing subgraphs being a spanning tree and alike graph theoretic features. Prsing a netlist posses no difficulty, but it looks like the digraph function does not care about the order in my input cells and when I plot the graph, it is labeled wrongly.

I have spent weeks on it with no result. Can you see a easy solution how to turn it into a graph object and plot it accordingly?

Code below produces obvisouly wrong plot, for instance resistors, while the topoogy seems to be idnetified correctly. Edges/Nodes are mislabeled.

Create and plot an oriented graph of a circuit from a netlist (3)

clear

close all

clc

netlist = {

'R1 N001 0 R';

'R2 N002 N001 R';

'R3 0 N002 R';

'C1 N002 N001 C';

'C2 N001 0 C';

'C3 N002 0 C';

'L1 N002 N001 L';

'L2 0 N001 L';

'L3 0 N002 L'

};

elements = {};

sourceNodes = {};

targetNodes = {};

labels = {};

for i = 1:length(netlist)

parts = strsplit(netlist{i});

elements{end+1} = parts{1};

sourceNodes{end+1} = parts{2};

targetNodes{end+1} = parts{3};

labels{end+1} = [parts{4} ' - ' parts{1}];

end

edgeTable = table(sourceNodes', targetNodes', labels', 'VariableNames', {'EndNodes', 'EndNodes2', 'Label'});

G = digraph(edgeTable.EndNodes, edgeTable.EndNodes2);

G.Edges.Label = edgeTable.Label;

h = plot(G, 'EdgeLabel', G.Edges.Label, 'NodeLabel', G.Nodes.Name, 'Layout', 'force');

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Steven Lord am 13 Aug. 2024 um 14:29

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist#answer_1498529

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist#answer_1498529

In MATLAB Online öffnen

Note that your list of sourceNodes and targetNodes only includes three unique entries: 0 (which I assume is ground), N001, and N002 (the two nodes on either side of L1, correct?)

netlist = {

'R1 N001 0 R';

'R2 N002 N001 R';

'R3 0 N002 R';

'C1 N002 N001 C';

'C2 N001 0 C';

'C3 N002 0 C';

'L1 N002 N001 L';

'L2 0 N001 L';

'L3 0 N002 L'

};

elements = {};

sourceNodes = {};

targetNodes = {};

labels = {};

for i = 1:length(netlist)

parts = strsplit(netlist{i});

elements{end+1} = parts{1};

sourceNodes{end+1} = parts{2};

targetNodes{end+1} = parts{3};

labels{end+1} = [parts{4} ' - ' parts{1}];

end

None of your resistors, capacitors, or loads (I assume that's what L1 through L3 are?) are nodes. Shouldn't they be? Or should the intermediate nodes between those components be nodes as well?

Continuing on with your code:

edgeTable = table(sourceNodes', targetNodes', labels', 'VariableNames', {'EndNodes', 'EndNodes2', 'Label'})

edgeTable = 9x3 table

EndNodes EndNodes2 Label ________ _________ __________ {'N001'} {'0' } {'R - R1'} {'N002'} {'N001'} {'R - R2'} {'0' } {'N002'} {'R - R3'} {'N002'} {'N001'} {'C - C1'} {'N001'} {'0' } {'C - C2'} {'N002'} {'0' } {'C - C3'} {'N002'} {'N001'} {'L - L1'} {'0' } {'N001'} {'L - L2'} {'0' } {'N002'} {'L - L3'}

G = digraph(edgeTable.EndNodes, edgeTable.EndNodes2);

The next line of your code is problematic. I've added one additional line before it so I can show you why it's problematic.

G.Edges % Show the edges table before

ans = 9x1 table

EndNodes ____________________ {'N001'} {'0' } {'N001'} {'0' } {'0' } {'N001'} {'0' } {'N002'} {'0' } {'N002'} {'N002'} {'N001'} {'N002'} {'N001'} {'N002'} {'N001'} {'N002'} {'0' }

G.Edges.Label = edgeTable.Label;

G.Edges % Show the edges table after

ans = 9x2 table

EndNodes Label ____________________ __________ {'N001'} {'0' } {'R - R1'} {'N001'} {'0' } {'R - R2'} {'0' } {'N001'} {'R - R3'} {'0' } {'N002'} {'C - C1'} {'0' } {'N002'} {'C - C2'} {'N002'} {'N001'} {'C - C3'} {'N002'} {'N001'} {'L - L1'} {'N002'} {'N001'} {'L - L2'} {'N002'} {'0' } {'L - L3'}

The second row in the G.Edges table before doesn't match the second row in edgeTable. You assume that the rows in the G.Edges table are in the same order as they appear in edgeTable. That is not necessarily the case; digraph reserves the right to reorder the Edges table.

Instead of disassembling edgeTable and adding the labels afterwards, why not build edgeTable in such a way that it's a valid value for the EdgeTable input of the digraph function? Then even if digraph needs to reorder the rows of the edges table, the Label variable is reordered so it remain synchronized with the EndNodes variable.

edgeTable = table([sourceNodes', targetNodes'], labels', 'VariableNames', {'EndNodes', 'Label'})

edgeTable = 9x2 table

EndNodes Label ____________________ __________ {'N001'} {'0' } {'R - R1'} {'N002'} {'N001'} {'R - R2'} {'0' } {'N002'} {'R - R3'} {'N002'} {'N001'} {'C - C1'} {'N001'} {'0' } {'C - C2'} {'N002'} {'0' } {'C - C3'} {'N002'} {'N001'} {'L - L1'} {'0' } {'N001'} {'L - L2'} {'0' } {'N002'} {'L - L3'}

G2 = digraph(edgeTable);

G2.Edges

ans = 9x2 table

EndNodes Label ____________________ __________ {'N001'} {'0' } {'R - R1'} {'N001'} {'0' } {'C - C2'} {'0' } {'N001'} {'L - L2'} {'0' } {'N002'} {'R - R3'} {'0' } {'N002'} {'L - L3'} {'N002'} {'N001'} {'R - R2'} {'N002'} {'N001'} {'C - C1'} {'N002'} {'N001'} {'L - L1'} {'N002'} {'0' } {'C - C3'}

If we plot G2 it still doesn't look like your original plot, but the labels are correct.

plot(G2, 'EdgeLabel', G2.Edges.Label)

Create and plot an oriented graph of a circuit from a netlist (5)

If you pictured that 0 as being much wider (the ground is not actually a single point), this actually does topologically match the original picture you showed.

Making each of the components an individual node, splitting the 0 ground node into one node for each component, using the layout function (to display it as a 'layered' graph), and/or explicitly specifying the 'XData' and 'YData' coordinates in the plot call would probably make it look closer to your original picture.

2 Kommentare

Keine anzeigenKeine ausblenden

Christine Tobler am 13 Aug. 2024 um 15:04

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist#comment_3236404

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist#comment_3236404

In MATLAB Online öffnen

Good catch, Steve! Yes, the Edges table is sorted, so the labels will not match the new sorted order.

Another syntax you could use here (only the last lines are modified):

netlist = {

'R1 N001 0 R';

'R2 N002 N001 R';

'R3 0 N002 R';

'C1 N002 N001 C';

'C2 N001 0 C';

'C3 N002 0 C';

'L1 N002 N001 L';

'L2 0 N001 L';

'L3 0 N002 L'

};

elements = {};

sourceNodes = {};

targetNodes = {};

labels = {};

for i = 1:length(netlist)

parts = strsplit(netlist{i});

elements{end+1} = parts{1};

sourceNodes{end+1} = parts{2};

targetNodes{end+1} = parts{3};

labels{end+1} = [parts{4} ' - ' parts{1}];

end

%% Modified code starting here:

Label = labels';

G = digraph(sourceNodes, targetNodes, table(Label));

h = plot(G, 'EdgeLabel', G.Edges.Label, 'NodeLabel', G.Nodes.Name, 'Layout', 'force');

Create and plot an oriented graph of a circuit from a netlist (7)

jf am 13 Aug. 2024 um 15:48

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist#comment_3236434

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2144929-create-and-plot-an-oriented-graph-of-a-circuit-from-a-netlist#comment_3236434

Very nice, indeed. Thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABGraphics2-D and 3-D Plots

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

  • digraph
  • circuit
  • netlist
  • spanning tree
  • graph plotting
  • spice
  • graph theory

Produkte

  • MATLAB

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Create and plot an oriented graph of a circuit from a netlist (9)

Create and plot an oriented graph of a circuit from a netlist (10)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

Create and plot an oriented graph of a circuit from a netlist (2024)
Top Articles
21+ Best Cruise Cabin Tips, Secrets, & Things to Know (Read Before Sailing)
When Is a Cruise Ship Balcony Worth It and When Is It Not?
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
Forozdz
O'reilly's Auto Parts Closest To My Location
Best Big Jumpshot 2K23
Craigslist Benton Harbor Michigan
Ashlyn Peaks Bio
Pj Ferry Schedule
What's Wrong with the Chevrolet Tahoe?
Bbc 5Live Schedule
Orlando Arrest and Public Records | Florida.StateRecords.org
Goldsboro Daily News Obituaries
Aktuelle Fahrzeuge von Autohaus Schlögl GmbH & Co. KG in Traunreut
Trini Sandwich Crossword Clue
Hood County Buy Sell And Trade
Erskine Plus Portal
Cbs Trade Value Chart Fantasy Football
Dexter Gomovies
Robert Deshawn Swonger Net Worth
Best Sports Bars In Schaumburg Il
Caring Hearts For Canines Aberdeen Nc
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
14 Top-Rated Attractions & Things to Do in Medford, OR
Afni Collections
Kqelwaob
Sinfuldeeds Vietnamese Rmt
Royals op zondag - "Een advertentie voor Center Parcs" of wat moeten we denken van de laatste video van prinses Kate?
Skip The Games Ventura
Marie Peppers Chronic Care Management
#1 | Rottweiler Puppies For Sale In New York | Uptown
Bay Focus
Mta Bus Forums
Midsouthshooters Supply
Stanford Medicine scientists pinpoint COVID-19 virus’s entry and exit ports inside our noses
Linda Sublette Actress
Ferguson Showroom West Chester Pa
5A Division 1 Playoff Bracket
Lucifer Morningstar Wiki
Coffee County Tag Office Douglas Ga
The Great Brian Last
Value Village Silver Spring Photos
Richard Mccroskey Crime Scene Photos
French Linen krijtverf van Annie Sloan
786 Area Code -Get a Local Phone Number For Miami, Florida
Prologistix Ein Number
Buildapc Deals
Ark Silica Pearls Gfi
Hy-Vee, Inc. hiring Market Grille Express Assistant Department Manager in New Hope, MN | LinkedIn
Overstock Comenity Login
Www.card-Data.com/Comerica Prepaid Balance
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 5535

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.