2개의 위치 벡터 xpos 및 ypos가 제공됩니다.x & y 위치 벡터에서 가능한 모든 조합을 보여주는 테이블을 만들고 싶습니다. 나는 가능한 모든 조합을 포함하는 2개의 새로운 벡터를 만들고자 하는 매우 간단한 예를 보여주고 있습니다. 내 문제는 인덱싱에서 비롯된 것으로 보이지만 당황했습니다.
// Want to create table showing all possible combinations from x & y position vectors
xpos={1, 2, 3, 4, 5};
ypos={7, 8, 9 };
xloc={};
yloc={};
// Loop through x positions
for(i=1, i<=NItems(xpos), i++,
// Loop through y positions
for(j=1, j<=NItems(ypos),j++,
insert into(xloc, xpos);
insert into(yloc, ypos, j);
);
//print(i);
);
xloc;
yloc;
dt = new table("All Combos");
dt << new column("X", continuous, values(xloc));
dt << new column("Y", continuous, values(y));
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Want a table that looks like this:
X Y
1 7
1 8
1 9
2 7
2 8
2 9
.
.
.
5 7
5 8
5 9
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~