I need to plot something that has nodes Numbers and Coordinates as in the attached file: Data_Coord.txt
the file has four columns and they correspond to: NodeNumber CoordX CoordY CoordZ, respectively
The conectivity between nodes is given by the file Data_Conec.txt
the file has three columns and they correspond to: ElementNumber Node1 Node2, respectively
Note that the number of the nodes is not sequential up to the total number of nodes, meaning that, for example, I could have node 1 conected to node 10001, even though I only have 200 nodes. but the coordinate of node 1 and 10001 is given on the Data_Coord.txt file and the first column specifies the number of the node.
How can I plot this 3D sketch?
I tried using digraph but because of the node numbers I wasnt sure how to proceed
thanks,

 Akzeptierte Antwort

Christine Tobler
Christine Tobler am 20 Jan. 2021

0 Stimmen

The easiest way to use graph/digraph when your node numbers are not sequential is to convert the node numbers to string, which will have them treated as node names instead. Then, you should be able to use digraph and hte plot command with 'XData', 'YData', and 'ZData' options.

3 Kommentare

Conrado Neto
Conrado Neto am 20 Jan. 2021
Hi Christine, thanks for your reply
this is what I tried, but I thought it wouldnt work given I change the node number to strings after the graph and plot commands, but it was the only solution I found:
G = digraph(E1,E2);
h = plot(G,'XData',X_Coord,'YData',Y_Coord,'ZData',Z_Coord,'ArrowSize',10); % ,'NodeLabel',1:100
labelnode(h,1:1965,Node_Coord)
which gave me the error message:
Error using matlab.graphics.chart.primitive.GraphPlot
Expected XData to be an array with number of elements equal to 1.11013e+06.
what is the proper way to do what you suggested? thanks again
Christine Tobler
Christine Tobler am 20 Jan. 2021
Bearbeitet: Christine Tobler am 20 Jan. 2021
Hi Conrado,
If E1, E2 are the second and third column of Data_Conec.txt, and Node_Coord is the first column of Data_Coord.txt, use
G = digraph(string(E1), string(E2), [], string(Node_Coord));
plot(G,'XData',X_Coord,'YData',Y_Coord,'ZData',Z_Coord,...
'ArrowSize',10,'NodeLabel',G.Nodes.Name);
Conrado Neto
Conrado Neto am 21 Jan. 2021
this works perfectly, thanks Christine!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by