How can I plot a truss using cartesian coordinates with lines connecting specific points
조회 수: 11 (최근 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!