How can I plot a truss using cartesian coordinates with lines connecting specific points
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
chicken vector
2023-4-28
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structural Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!