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.

採用された回答

chicken vector
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 ExchangeStructural Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by