【发布时间】:2011-09-06 10:21:53
【问题描述】:
我有两个问题,
第一季度。 代码如下:
orgtable = Table[{i, node2 = i + 1, node3 = node2 + 6, node4 = node3 - 1,
node5 = i + 18, node6 = node5 + 1, node7 = node6 + 6,
node8 = node7 - 1}, {i, 1, 36}
];
modtable = Drop[orgtable, {6, 36, 6}];
finaltable = With[{n = 5, m = 10},Flatten[Partition[modtable, n, n + m, 1, {}], 1]]
第一段代码给了我一个原始表格,第二段给了我一个修改过的表格,第三段产生了最终表格。 决赛桌的输出如下所示:
{{1, 2, 8, 7, 19, 20, 26, 25}, {2, 3, 9, 8, 20, 21, 27, 26},
{3, 4, 10, 9, 21, 22, 28, 27}, {4, 5, 11, 10, 22, 23, 29, 28},
{5, 6, 12,11, 23, 24, 30, 29}, {19, 20, 26, 25, 37, 38, 44,43},
{20, 21, 27,26, 38, 39, 45, 44}, {21, 22, 28, 27, 39, 40, 46, 45},
{22, 23, 29,28, 40,41, 47, 46}, {23, 24, 30, 29, 41, 42, 48, 47}}
但我希望它为决赛桌设置一个计数器,这样我的输出应该如下所示:计数器将增加 1,在下面的示例中,它将从 200 开始;
{{200,1, 2, 8, 7, 19, 20, 26, 25}, {201,2, 3, 9, 8, 20, 21, 27, 26},
{202,3, 4,10, 9, 21,22, 28, 27}, {203,4, 5, 11, 10, 22, 23, 29, 28},
{204,5, 6, 12,11, 23, 24, 30, 29} and so on
从所需的输出中可以看出,每个元素的计数都会增加一
现在第二个问题:
mycounter = 100;
tryone =
TableForm[
Flatten[
Table[{++mycounter, xcord, ycord,
(150*(Sin[((xcord - 90*2*3.14)/180]^2)*
(Sin[((ycord - 45)*2*3.14)/180]^2)
) + 20
}, {xcord, 0, 200, 5}, {ycord, 0, 200, 5}
], 1
]
]
在上面的例子中,我已经成功实现了一个计数器,它从 100 开始并以 1 递增,它给了我一个输出
100 0 0 20.03
101 0 5 20.04 and so on..
但现在我想对此使用Transpose 函数,因为我想转置呈现的值,但同时我不想转置“我的计数器”。
mycounter = 100;
secondtry=
TableForm[
Flatten[
Transpose[
Table[{++mycounter, xcord, ycord,
(150*(Sin[((xcord - 90)*2*3.14)/180]^2)*
(Sin[((ycord - 45)*2*3.14)/180]^2)
) +20}, {xcord, 0, 200, 5}, {ycord, 0, 200, 5}
]
], 1
]
]
但正如您所见,Transpose 函数也会转置我不想要的“mycounter”。 如何防止转置功能在“mycounter”上工作,但在其余部分工作? 也欢迎在上述代码中实现计数器的任何其他想法。
【问题讨论】:
-
@Sjoerd ...你赢得了编辑比赛:)
-
@belisarius 我们不应该得到一个橙色条警告我们正在同时编辑吗?没看到。
-
@Sjoerd 我做到了。但仅在尝试保存编辑时。
标签: list wolfram-mathematica counter nested-lists