VSum
The VSum function returns the sum of a variable list that can include values, tables, and data collection objects. If the list consists only of a single large table or class object, use the faster TSum function.
nSum = VSum( ... )
where
... is a list of numbers, tables, CImage, CArray, and CMatrix objects.
nSum is the sum of the values from all items in the list.
To process a single table, or a single CImage, CArray, or CMatrix object, use TSum function or the CStats:Mean method. Using the CStats class has the added ability to constrain the sample to a rectangular region of a CImage. CArray, or CMatrix object. Since Lua implicitly converts string representations of numbers to numbers, the argument list and tables also may contain strings that can be converted to numbers.
The following script returns the sum of values in acollection of tables and numbers. Note that table t is used twice in the argument list just for testing purposes.
|
-- create atable |
|
-- create another table |
|
-- createsome subtables |
|
-- create a table with strings as numbers |
|
-- assemble tables into another table |
|
-- call VSum() with an argument list |
|
-- Result: Sum = 215.0003 |