Finding length between two matrix rows

6 ビュー (過去 30 日間)
Carly
Carly 2016 年 10 月 7 日
編集済み: Carly 2016 年 10 月 7 日
I'm trying to find the length of beams in a 2D structure. All the joints in the structure are specified in a matrix, 'jointCoords' where the columns are the x and y coordinates and the rows are joints 1-n. This matrix does not always have four rows, it can be any number of rows long depending on the structure.
jointCoords = [ 0 0 % Coordinates of joint 1: (0,0)
10 0 % Coordinates of joint 2: (10,0)
0 8 % Coordinates of joint 3: (0,8)
6 8] ; % Coordinates of joint 4: (6,8)
The second matrix, 'members' specifies the beginning joint number, end joint number, as well as young's modulus and cross sectional area of the beam, where the first column of the first row is the beginning joint number of beam 1 and the second column of the first row is the end joint number of beam 1
members = [ 1 3 1 1 % First member
3 4 1 1 % Second member
1 4 1 1 % ...
2 3 1 1
2 4 1 1];
In these particular matrices, the 1 in the first row and column of 'members' means the the beginning joint of beam 1 is located at the coordinates specified by the row 1 in 'jointCoords' which would be (0,0) in this case
Since columns 3 and 4 of 'members' are not of use for calculating length I made a third matrix with just the joint numbers:
memberJoints=members(:,1:2)
I'm not sure this is the correct way to specify all of the first two columns of 'memberJoints' but I wanted the matrix to look like this
memberJoints = [1 3
3 4
1 4
2 3
2 4]
I now need to find the distance between the beginning and end joints of each member, as specified by the beginning and end coordinates of each member which are named in memberJoints. For example, the length of beam 1 is the distance between joint 1 and joint 3. Joint 1 is located at (0,0) and joint 3 is located at (0,8). I know pdist would give me the distance between the two points, but I'm not sure how to specify the two points based on what's in each row of 'memberJoints'. I think this should be in a for loop based on what I need to do after I find the length of each member, but remember that the number of members and joints is not always the same as what is in these two matrices.

採用された回答

Stalin Samuel
Stalin Samuel 2016 年 10 月 7 日
jointCoords = [ 0 0 % Coordinates of joint 1: (0,0)
10 0 % Coordinates of joint 2: (10,0)
0 8 % Coordinates of joint 3: (0,8)
6 8] ; % Coordinates of joint 4: (6,8)
memberJoints = [1 3
3 4
1 4
2 3
2 4]
for it=1:length(memberJoints)
n1=memberJoints(it,1);
n2=memberJoints(it,2);
distance(it)=pdist([jointCoords(n1,1),jointCoords(n2,1); jointCoords(n1,2),jointCoords(n2,2)],'euclidean')
end
  1 件のコメント
Carly
Carly 2016 年 10 月 7 日
編集済み: Carly 2016 年 10 月 7 日
Thanks, this really helped! Although, I think the pdist line should have been
distance(i)=pdist([jointCoords(n1,1),jointCoords(n1,2); jointCoords(n2,1),jointCoords(n2,2)],'euclidean')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePoint Cloud Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by