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

  1. Table table = Table("GlobalTable1");
  2. int row = 1;
  3. int smallestColumn = 1;
  4. double smallestNumber = table[row][1];
  5.  
  6. for (int i = 2; i <= table.numCols; i++) {
  7. double curNumber = table[row][i];
  8. if (curNumber < smallestNumber) {
  9. smallestNumber = curNumber;
  10. smallestColumn = i;
  11. }
  12. }
  13. 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.