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

44 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
Nikki Catsouras: The Tragic Accident And The Infamous Real Photo
Warning: Graphic Content - Nikki Catsouras Fatal Crash Photos
Poe T4 Aisling
Mountain Dew Bennington Pontoon
Lost Ark Thar Rapport Unlock
Truist Drive Through Hours
Little Rock Arkansas Craigslist
Blue Beetle Showtimes Near Regal Swamp Fox
Med First James City
Rainfall Map Oklahoma
Ts Lillydoll
Mail.zsthost Change Password
Houses and Apartments For Rent in Maastricht
Ups Access Point Lockers
Rugged Gentleman Barber Shop Martinsburg Wv
Wgu Academy Phone Number
Robert Deshawn Swonger Net Worth
Iroquois Amphitheater Louisville Ky Seating Chart
Samantha Aufderheide
Walmart Near South Lake Tahoe Ca
Bento - A link in bio, but rich and beautiful.
2000 Ford F-150 for sale - Scottsdale, AZ - craigslist
Meta Carevr
JVID Rina sauce set1
Anesthesia Simstat Answers
Stouffville Tribune (Stouffville, ON), March 27, 1947, p. 1
Swgoh Boba Fett Counter
Sf Bay Area Craigslist Com
Siskiyou Co Craigslist
Rocksteady Steakhouse Menu
Tra.mypatients Folio
Black Adam Showtimes Near Amc Deptford 8
Chilangos Hillsborough Nj
Go Smiles Herndon Reviews
Scanning the Airwaves
The best Verizon phones for 2024
D-Day: Learn about the D-Day Invasion
Discover Wisconsin Season 16
Appraisalport Com Dashboard Orders
Hkx File Compatibility Check Skyrim/Sse
15 Best Places to Visit in the Northeast During Summer
Xre 00251
The Machine 2023 Showtimes Near Roxy Lebanon
Dobratz Hantge Funeral Chapel Obituaries
Mcoc Black Panther
Walmart Front Door Wreaths
Star Sessions Snapcamz
2487872771
Home | General Store and Gas Station | Cressman's General Store | California
Zalog Forum
Acellus Grading Scale
All Obituaries | Roberts Funeral Home | Logan OH funeral home and cremation
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6500

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.