question

Claire Krupp avatar image
0 Likes"
Claire Krupp asked Claire Krupp commented

How to get the average from a local tracked variable in a Global Table?

I have a global Table where some of the columns are Tracked Variables. I want to access the average of each cell of "T between shuttles" and store it in the next column. The manual tells me how to do this for a Global Tracked Variable, but it is not working for the local one.

Here is the table: the column "T between shuttles" is the tracked variable and "Avg TBS" is where I want to store the average.

This is the Custom Code I have tried.

/* Calculate TBS, store in table */
Variant value = Model.time - table[row]["Leave time"];
table[row][column] = value;
/* get average value, store in next column */
 TrackedVariable trackedVar = table[row][column];
double avg = trackedVar.average;
table[row]["Avg TBS"] = avg;


When the logic gets to "trackedVar" it gives a "Null" value for it.

If I try using "avg = table[row][column].average;" the error message says you can't use .average with a table.

I can't find any other explanation of this in the manual.

FlexSim 19.1.0
global tabletracked variables
stats-table.png (128.1 KiB)
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

Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Claire Krupp commented

Try using the cell() method on the table class, and cast the node as a TrackedVariable:

table.cell(row, column).as(TrackedVariable).average

The [] operators get the value of the cell. In your case, the [] operators are returning the value of the tracked variable, where you want the tracked variable itself.

· 1
5 |100000

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

Claire Krupp avatar image Claire Krupp commented ·

That did the trick! Thank you.

0 Likes 0 ·