Hello everyone. I have a list of 3d vectors representing positions in space and need to generate an array (A) with the following form.
In 2d: X=[X0 X1 X2 ... Xn] Y=[Y0 Y1 Y2 ... Yn]
A=[X0 Y0; X0 Y1; X0 Y2; X1 Y0; X1 Y1; X1 Y2; X2 Y0; X2 Y1; X2 Y2; ... ; Xn Yn]
As mentioned, I'll actually need it in 3d. I provided the 2d example for simplicity.
Thank you for your help!!

댓글 수: 2

Walter Roberson
Walter Roberson 2018년 7월 1일
Is every X to be used with every Y, or is it only adjacent coordinates? Like *2 linked to *1, *2, *3 but not *0 ?
B Rogers
B Rogers 2018년 7월 1일
Every X is paired with every Y.

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

 채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 1일

0 개 추천

For the case of every point linked to every other point:
[T1, T2, T3] = ndgrid(X, Y, Z);
A = [T1(:), T2(:), T3(:)];

댓글 수: 1

B Rogers
B Rogers 2018년 7월 1일
I knew there must be a way easier than how I was trying to do it. This works perfectly. Thank You Walter.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 7월 1일

댓글:

2018년 7월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by