ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
|
Downloads |
Tips and Tricks Share helpful modeling ideas |
#1
|
||||
|
||||
Using multi-dimensional arrays with flexscript
There are no multi-dimensional arrays in flexscript per se; however the script shown below can be helpful when working with multi-dimensional data. It basically takes a one dimensional array and sets it up to be referenced as if it were a two dimensional array. You can extend this concept to further dimensions as well.
//The following two macros named ROW and COL can be defined within // the code, or defined globally in Tools>Global Variables>Global Macros. // If defined globally, they will show in a different color which is useful. #define ROW (cols+1)* #define COL + int cols = 5; int rows = 20; doublearray myarray = makearray((cols+1)*(rows+1)); myarray[ ROW 1 COL 1] = 4.3; myarray[ ROW 1 COL 2] = 4.4; myarray[ ROW 1 COL 3] = 4.5; myarray[ ROW 1 COL 4] = 4.6; myarray[ ROW 1 COL 5] = 4.7; myarray[ ROW 2 COL 1] = 5.3; myarray[ ROW 2 COL 2] = 5.4; myarray[ ROW 2 COL 3] = 5.5; myarray[ ROW 2 COL 4] = 5.6; myarray[ ROW 2 COL 5] = 5.7; for(int i = 1; i <= 2; i++) { for(int j = 1; j <= 5; j++)} The printout is as follows: row 1 col 1 4.300000 row 1 col 2 4.400000 row 1 col 3 4.500000 row 1 col 4 4.600000 row 1 col 5 4.700000 row 2 col 1 5.300000 row 2 col 2 5.400000 row 2 col 3 5.500000 row 2 col 4 5.600000 row 2 col 5 5.700000 Last edited by Cliff King; 12-15-2007 at 11:35 AM. |