我设法将2d数组转换为1d数组以使其更简单。因此给出:
local table = {0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,0,30,31,32,33, 0,34,35,36,37, 0 }
如何提取如下的子数组?
local sub = {2,3,4,7,8,9,12,13,14,17,18,19,22,23,24}
答案 0 :(得分:2)
这是一种方法...
> t = {}
> for i = 7, 30, 5 do
>> for j = i, i + 2 do
>> t[#t+1] = ble[j]
>> end
>> end
> for k,v in ipairs(t) do print(k,v) end
1 2
2 3
3 4
4 7
5 8
6 9
7 12
8 13
9 14
10 17
11 18
12 19
13 22
14 23
15 24
>
我将您的表重命名为ble
,因此它不会隐藏表库。