question

Maíra A avatar image
0 Likes"
Maíra A asked Maíra A commented

Can i return the column of a specific number in a global table?

I would like to return the column that contains the lowest number in a specific row. How can i do that preferentially using the code editor inside the assign label?

flexsim-column.fsm

FlexSim 19.0.0
global tablecode editor
flexsim-column.fsm (20.6 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

Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Maíra A commented

You can do this with a single for loop in the Value field of the Assign Labels activity:

smallestcolumn.fsm

Table table = Table("GlobalTable1");
int row = 1;
int smallestColumn = 1;
double smallestNumber = table[row][1];

for (int i = 2; i <= table.numCols; i++) {
	double curNumber = table[row][i];
	if (curNumber < smallestNumber) {
		smallestNumber = curNumber;
		smallestColumn = i;
	}
}
return smallestColumn;

smallestcolumn.fsm (18.8 KiB)
· 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.

Maíra A avatar image Maíra A commented ·

@Matthew Gillespie This was exactly what i needed! Thank you so much!

0 Likes 0 ·