1 回答
TA贡献1875条经验 获得超3个赞
对于每个m您重置i为 0 并再次开始在数组开头写入的内容。
递增时需要继续向前移动索引m。
组合两个索引时也是如此。当您组合两次迭代以获得索引时,通常将第一次乘以第二次的长度,然后将它们加在一起。
for (int m = 0; m < Weights.Length; m++)
{
int offset = m * Cranelocations.GetLength(0);
for (int i = 0; i < Cranelocations.GetLength(0); i++)
{
for (int j = 0; j < Picklocation.GetLength(0); j++)
{
double x = Cranelocations[i, 0] - Picklocation[j, 0];
double y = Cranelocations[i, 1] - Picklocation[j, 1];
result1[i + offset, j] = Weights[m] * (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)));
}
}
}
Console.WriteLine("-----------------------------------------------------------------");
for (int m = 0; m < Weights.Length; m++)
{
int offset = m * Cranelocations.GetLength(0);
for (int i = 0; i < Cranelocations.GetLength(0); i++)
{
for (int j = 0; j < Setlocation.GetLength(0); j++)
{
double x = Cranelocations[i, 0] - Setlocation[j, 0];
double y = Cranelocations[i, 1] - Setlocation[j, 1];
result2[i + offset, j] = Weights[m] * (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)));
}
}
}
for (int i = 0; i < result1.GetLength(0); i++)
{
int iOffset = i * result1.GetLength(1);
for (int j = 0; j < result1.GetLength(1); j++)
{
for (int k = 0; k < result2.GetLength(0); k++)
{
int kOffset = k * result2.GetLength(1);
for (int m = 0; m < result2.GetLength(1); m++)
{
result3[iOffset + j, kOffset + m] = result1[i, j] + "," + result2[k, m];
Console.WriteLine(result3[iOffset + j, kOffset + m]);
counter++;
}
}
}
}
- 1 回答
- 0 关注
- 129 浏览
添加回答
举报