Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to construct all possible combinations of points in N-dimensional space

1 回表示 (過去 30 日間)
mohamed Faraj
mohamed Faraj 2020 年 7 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have x-y coordinates of 3 points, e.g, (x1,y1,0),(x2,y2,0), and (x3,y3,0). I want to construct other points on top of these 3 points at fixed z locations, e.g., every z=4. So, in total we have 3*N points. For example, if N=2, we have 6 points in total at locations (x1,y1,0),(x2,y2,0), (x3,y3,0),(x1,y1,4),(x2,y2,4), and (x3,y3,4). After that, I want to find the distance between every two points and arrange these distances in a symmetric matrix which looks like [d11 d12 d13 d14 d15 d16;d21 d22 d23 d24 d25 d26...]. Note that d12=d21..etc.Here, I give an example of 3 points as a basis to start with but it could be much larger. What is the most efficient way to construct this?. Appreciate it

回答 (1 件)

Matt J
Matt J 2020 年 7 月 22 日
X=[x1,x2,x3].';
Y=[y1,y2,y3].';
[I,J]=ndgrid(1:3,4*(0:N-1) );
P=[X(I(:)),Y(I(:)), J(:)];
d=pdist2(P,P);
  2 件のコメント
mohamed Faraj
mohamed Faraj 2020 年 7 月 22 日
Thanks Matt. I have 2013 matlsb. pdist2 is not available. Any other suggestion please.
Matt J
Matt J 2020 年 7 月 22 日
You can use the attached file instead.
d=interdists(P.');

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by