How can I plot a truss using cartesian coordinates with lines connecting specific points
14 views (last 30 days)
Show older comments
Scott Pasfield
on 28 Apr 2023
Commented: Scott Pasfield
on 28 Apr 2023
Hi, I'm trying to create a plot that uses the below variables. The nodes matrix represents the location and the elements matrix specifies which nodes are connected.
% x and y nodal coordinates
nodes = [ 0.0 , 0.0; 1.5 , 3.3; 3.0 , 2.0; 4.5 , 3.9; 6.0 , 2.0; 7.5 , 3.3; 9.0 , 0.0];
% element connectivity
elems = [ 1.0 , 2.0; 1.0 , 3.0; 2.0 , 3.0; 2.0 , 4.0; 3.0 , 4.0; 3.0 , 5.0; 4.0 , 5.0; 4.0 , 6.0; 5.0 , 6.0; 5.0 , 7.0; 6.0 , 7.0 ];
The code below shows the outcome I want but is tedious and prone to errors as it requires me to plan the path and also backtrack as it is a continuous line.
x = [nodes(2,1) ; nodes(3,1) ; nodes(1,1) ; nodes(2,1) ; nodes(4,1) ; nodes(3,1) ; nodes(5,1) ; nodes(4,1) ; nodes(6,1) ; nodes(5,1) ; nodes(7,1) ; nodes(6,1) ;];
y = [nodes(2,2) ; nodes(3,2) ; nodes(1,2) ; nodes(2,2) ; nodes(4,2) ; nodes(3,2) ; nodes(5,2) ; nodes(4,2) ; nodes(6,2) ; nodes(5,2) ; nodes(7,2) ; nodes(6,2) ;] ;
plot(x,y)
Thanks for any help.
0 Comments
Accepted Answer
chicken vector
on 28 Apr 2023
nodes = [ 0.0 , 0.0; 1.5 , 3.3; 3.0 , 2.0; 4.5 , 3.9; 6.0 , 2.0; 7.5 , 3.3; 9.0 , 0.0];
elems = [ 1.0 , 2.0; 1.0 , 3.0; 2.0 , 3.0; 2.0 , 4.0; 3.0 , 4.0; 3.0 , 5.0; 4.0 , 5.0; 4.0 , 6.0; 5.0 , 6.0; 5.0 , 7.0; 6.0 , 7.0 ];
figure;
hold on;
for el = 1 : length(elems)
plot(nodes(elems(el,:),1),nodes(elems(el,:),2),'b')
end
hold off;
You also might want to have a look at graph function.
More Answers (0)
See Also
Categories
Find more on Structural Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!