question

Pieter Cecat avatar image
0 Likes"
Pieter Cecat asked Pieter Cecat commented

Multiply two tables

How can I most easily multiply the values of two global tables in a new table?

1/ when dimensions of both tables are the same.

2/ when a table has many rows but only 1 has to be multiplied with another table with 1 row.

Thanks in advance!

FlexSim 16.0.8
dashboardsglobal tablesgraphs
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Pieter Cecat commented

Here is a script you can run:

  1. treenode table1 = reftable("GlobalTable1");
  2. treenode table2 = reftable("GlobalTable2");
  3. treenode table3 = reftable("GlobalTable3");
  4.  
  5. for(int i = 1; i <= gettablerows(table1); i++){
  6. for(int j = 1; j <= gettablecols(table1); j++){
  7. int value = gettablenum(table1, i, j) * gettablenum(table2, i, j);
  8. settablenum(table3, i, j, value);
  9. }
  10. }

If you only want to do the first row change i <= gettablerows(table1) to i <= 1.

If you upgrade to 17.0 you can use dot syntax:

  1. Table table1 = reftable("GlobalTable1");
  2. Table table2 = reftable("GlobalTable2");
  3. Table table3 = reftable("GlobalTable3");
  4.  
  5. for(int i = 1; i <= table1.numRows; i++){
  6. for(int j = 1; j <= table1.numCols; j++){
  7. table3[i][j] = table1[i][j] * table2[i][j];
  8. }
  9. }
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.