Im trying to find the distance between 2 points on a truss and I have the length and the x and y of the nodes on the truss but what code in matlab would make this work.
I know
d = sqtrt((x2-x1)^2+(y2-y1)^2) ;
But how would I apply it to an array on a truss
with x being the nodes and e being the edges or lines that connect nodes
X = [0 0
1 0
2 0
2 1
1 1
0 1
];
e = [1 2
2 3
3 4
4 5
5 6
6 1
2 4
3 5
1 5
2 6];
I just dont seem to get how to put these two together and make a distance formula that works. The lengths of these points are the outside lengths are 1 m and the cross section lengths are the sqrt of 2(these inside ones being from 1 to 5, 6 to 2, 4 to 2, and 5 to 3.

댓글 수: 7

Rik
Rik 2022년 3월 28일
Which distance do you want to calculate? Your array X encodes x and y coordinates, so that is what you should end up using, but first you need to be able to tell what exactly you want to know.
Thats kinda the problem. I need to know the length of each section of the truss and be abble to put them into an array to use to find how the breaking point occurs.
Rik
Rik 2022년 3월 28일
So you need the length of each section? I would suggest looping through the rows of your e array. Those are indices to your X array, which contain the x and y coordinates.
Kaden Bauernfeind
Kaden Bauernfeind 2022년 3월 28일
ok and how would I go about that I'm really not the best with Matlab. and thank you for the help
Rik
Rik 2022년 3월 28일
Which part is causing you trouble? Writing a loop? Indexing? Try something and I will help you get to the result.
Kaden Bauernfeind
Kaden Bauernfeind 2022년 3월 28일
writing a loop
I under stand that it would be a for loop but how I would apply the i is kinda what confuses me
example
for i = 1:n
i know thats how its formated I just dont know what the 1:n means.
Rik
Rik 2022년 3월 28일
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). That should help with tasks like this.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2022년 3월 28일

0 개 추천

A=pdist2(X,X);
distances = A( sub2ind(size(A) ,e(:,1),e(:,2) ) )

카테고리

도움말 센터File Exchange에서 Structural Analysis에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 3월 28일

댓글:

Rik
2022년 3월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by