View Full Version : Does there exist a function that can calculate the time weighted average of a value in a Global tabl
qin tian
01-16-2008, 12:14 AM
I have a value in a Global table. The value changes through time.
I want to calculate the time weighted average of the value as a PFM in the experimenter tool.
But I cannot find a function to do this.
Does there exist a function that can calculate the time weighted average of a value in a Global table?
Cliff King
01-18-2008, 01:50 PM
There are no functions that calculate a time weighted average, but the formula is pretty easy: A = (V1*T1 + V2*T2 + ...) / TotalTime
You could also use the Recorder object which will dynamically calculate a running weighted average by time or by occurence. Choose these options on the Recorder:
Type of Data: User-defined Data
Output type: Min/Max/Average
Weight averages by time
qin tian
01-19-2008, 01:00 AM
Thanks,Cliff.
Yes, now I am using recorder to get the value.
Then I want to get the value of recorder in the experimenter PFM trigger.
I use the getnodenum() function to get the value of the recorder.
But it doesn't work. Below is what I use.
getnodenum(node("/Recorder1>variables>graphdata>MAIN:/project/model/Tools/GlobalTables/Table1/variables/data/total/1/AvgValue", model()));
The function doesn't return correct.
Why? How to reslove it? Please help.
Cliff King
01-19-2008, 11:05 AM
Unfortunately the name of the row node in the graphdata table variable of a Recorder object happens to be the path to the node(s) it is recording, which in your case is MAIN:/project/model/Tools/GlobalTables/Table1/variables/data/total/1. This confuses Flexsim when it tries to follow the path in your getnodenum(node()) expression as you can imagine. You also made the mistake of using > when you needed to use /. Remember that > is used to "dive" into the object data of a node, and / is used to simply drop down one level in hierarchy.
I suggest you refer to the row node in the graphdata table by rank instead of name. In a string defining the path to a node, if the first character following a special character is a number then it is interpreted as the rank of the next node rather than the name. So in other words, if your recorded variable is in the sixth row of the graphdata table, you could use this expression:
getnodenum(node("/Recorder1>variables/graphdata/6/AvgValue", model()));
As a tip, one sure way to get the full path to a node in the tree using all ranks is to right-click on the node in the tree and choose Edit | Designate This Node so(), then from a Script window type nodetopath(so(),0); and hit Execute. You can then copy the string from the window and paste it directly into node(" ") This will always work so long as you do not change the ranks of any nodes refered to in the path. Those nodes which might change rank in the model, you will need to replace the rank number with the name of the node/object.
This will
qin tian
01-20-2008, 06:01 PM
Great,thank you Cliff.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.