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:

treenode table1 = reftable("GlobalTable1");
treenode table2 = reftable("GlobalTable2");
treenode table3 = reftable("GlobalTable3");

for(int i = 1; i <= gettablerows(table1); i++){
	for(int j = 1; j <= gettablecols(table1); j++){
		int value = gettablenum(table1, i, j) * gettablenum(table2, i, j);
		settablenum(table3, i, j, value);
	}
}

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:

Table table1 = reftable("GlobalTable1");
Table table2 = reftable("GlobalTable2");
Table table3 = reftable("GlobalTable3");

for(int i = 1; i <= table1.numRows; i++){
	for(int j = 1; j <= table1.numCols; j++){
		table3[i][j] = table1[i][j] * table2[i][j];
	}
}
· 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.

Pieter Cecat avatar image Pieter Cecat commented ·

Is it possible to run the script automatically everytime I run the model?

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Pieter Cecat commented ·

You could put the code in an OnReset or OnRunStart trigger (Toolbox >Add > Modelling Logic > Model Trigger)

2 Likes 2 ·
Pieter Cecat avatar image Pieter Cecat commented ·

Nevermind I already found it:

A FlexSim model has an On Run Stop. Here I put the logic.

Thanks

0 Likes 0 ·