subn


The subn function subtracts a value from a general lua table that may contain a multi-dimensional array or a mixture of numbers, strings, named keys, and sub-tables. Only numeric values found in the table are used in the calculation. The related sub function subtracts a number to a 1-dimensional array, CImage, or list of numbers. Since an array is a specific type of table that contains only numbers or sub-tables, this function can also be used for arrays.

Syntax

new_table = subn( tbl, value )

bullet.gif    tbl is a general lua table.

bullet.gif    value is a number.

bullet.gif    new_table is returned as a table.

Examples

The following script subtracts 3200.5 from all members of a 1-dimensional array.

t = random(10000)

-- create 10000 random numbers

t = subn( t, 3200.5 )

-- subtract 3200.5 from all members of the array

  

The next script subtracts 3200.5 from the values in a complex, ugly table:

t = { 6, -2, 15, "a", {5,"b"}, c="5.4" }

 

tnew = subn(t, 3200.5)

-- subtract 3200.5

Related Topics

Table and Array Functions

addn

sub


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.