question

Pinakin K avatar image
0 Likes"
Pinakin K asked Joshua S answered

How to update global table with Array?

I want to write the he values in Array form in the Global Table. the Array index is also not fixed, it is decided by a discrete uniform distribution with min 1 and max 5. The values for each index in the array also follow a Duniform distribution with min 1200 and max 3000.

this array would be referenced in the process flow, so it should also be a tracked variable. How should I proceed?

FlexSim 18.0.3
global tablearraytracked variables
· 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.

Pinakin K avatar image Pinakin K commented ·

@Joshua S and @Jacob Gillespie it worked Thanks!

0 Likes 0 ·

1 Answer

Joshua S avatar image
0 Likes"
Joshua S answered

To allow cells in a Global Table to have Array values, select the cells you want to set, then right click and follow the tabs shown in the picture below.

Then to reference that data use the following statement.

Table("GlobalTable1")[Row][Column].as(Array)[Index]

Hope this helps to get started.


pic1.png (18.1 KiB)
· 4
5 |100000

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

Pinakin K avatar image Pinakin K commented ·

How can I define the index in custom code, i did this, but it won't go further than line 5, and its giving error message :

FlexScript exception: Array index out of bounds at MODEL:/Tools/ProcessFlow/ProcessFlow/Custom Code>variables/codeNode

int TerminalsPerSgmnt = 0;
int NoOfSplices = dempirical("NoOfSplices");
Table("TerminalCount")[reel2][5] = NoOfSplices;
int NoOfSgmnts = NoOfSplices + 1;
Table("TerminalCount")[reel2][10].as(Array)[NoOfSgmnts];


for(int Index = 1; Index <= NoOfSgmnts; Index ++ )
{
	if(Index < NoOfSgmnts)
	{
		Table("TerminalCount")[reel2][10].as(Array)[Index] = normal(Table("TerminalReels")[reel2][1]/NoOfSplices, 100,0);
		TerminalsPerSgmnt += Table("TerminalCount")[reel2][10].as(Array)[Index];
		Table("TerminalCount")[reel2][10].as(Array)[Index] = round(Table("TerminalCount")[reel2][10].as(Array)[Index],0);
	}
	else
	{
		Table("TerminalCount")[reel2][10].as(Array)[Index] = Table("TerminalReels")[reel2][1] - TerminalsPerSgmnt;
		Table("TerminalCount")[reel2][10].as(Array)[Index] = round(Table("TerminalCount")[reel2][10].as(Array)[Index],0);
	}
}

0 Likes 0 ·
Joshua S avatar image Joshua S Pinakin K commented ·

Can you upload your model or Tables so we can walk the code line by line? One guess is that you tried to index an array value that was larger than the length of your array, this might have been done in line 4.

0 Likes 0 ·
Pinakin K avatar image Pinakin K Pinakin K commented ·

How should I give the length of the array?

0 Likes 0 ·
Jacob Gillespie avatar image Jacob Gillespie ♦ Pinakin K commented ·

@Pinakin K You need to initialize the array to be the size you want. This could be done in the OnReset trigger of the table.

You would do something like this:

Table("TerminalCount")[reel2][10] = Array(5).fill(0);
1 Like 1 ·