其他分享
首页 > 其他分享> > tuple数组

tuple数组

作者:互联网

* simple assignment of the result of an expression to a variable

Val := sin(1.2) + cos(1.2)
* 
* assign a tuple to a variable
*初始化数组
Tuple1 := [1,0,3,4,5,6,7,8,9]
* 
* assign a value to a single element of a tuple
*修改数组的值
Tuple1[1] := 2
* 
* assign one value to several tuple elements
*分别修改1,3,5编号的值
Tuple1[1,3,5] := 'abc'
* 
* assign several values to several tuple elements at the same time
*分别修改0,4,8编号的值
Tuple1[0,4,8] := ['000','444','888']
* 
* setting a value beyond the tuple's range will initialize the
* intermediate values
*数组2的第5编号为5,编号0-4默认为0
Tuple2[5] := 5
* 
* initialize a tuple via a loop
dev_update_off ()
count_seconds (Tb)
*初始化数组3,然后依次存入数据,这里有可能会出现数组空间扩展重新拷贝,会影响效率
Tuple3 := []
for i := 0 to 10000 by 1
    Tuple3[i] := i * i
endfor
count_seconds (Te)
T1 := Te - Tb
stop ()
* 
* use a more efficient version of loop initialization
* which avoids the realocation of the tuple
count_seconds (Tb)
*先生成足够长的数组长度
Tuple3 := gen_tuple_const(10001,0)
for i := 0 to 10000 by 1
    Tuple3[i] := i * i
endfor
count_seconds (Te)
T2 := Te - Tb
stop ()
* 
* even better initialization without a loop by generating
* a tuple sequence
count_seconds (Tb)
*预先分配的另一种实现方式
Tuple3 := [0:10000]
Tuple3 := Tuple3 * Tuple3
count_seconds (Te)
T3 := Te - Tb
* 
* other ways for initializing sequence tuples with different steps
*生成从3到5的数组,间距增幅是0.1
Tuple4 := [3:0.1:5]
*生成100到-100的数组,间距是-10
Tuple5 := [100:-10:-100]

 

*生成数组
Tuple1 := [1,2,3,4,5]
*获取数组长度
Number := |Tuple1|
*获取编号为3的元素,这里值是4
SingleElement := Tuple1[3]
*截取部分数组,这里是2,3,4三个数据组成的数组
Part := Tuple1[1:3]
*这里是拷贝全数组,因此是1,2,3,4,5
Copy := Tuple1[0:|Tuple1| - 1]

 

标签:count,tuple,seconds,Tuple1,Tuple3,数组
来源: https://www.cnblogs.com/gspuser/p/13718732.html