LabVIEW programming topics - elements in arrays
Using arrays (1)
The following vi demonstrates how to intialize and change the elements of a 20x20 array.
The following steps describe how to create this vi.
- Open a new vi.
- Go to the block diagram and add a sequence structure.
- Use frame 0 (at this stage actually without number) to initialize the array. Here an array with 20 rows and 20 columns is filled with 1's.
- Put a 'Initialize Array' node inside the frame. Pop up on the 'Initialize Array' node and select 'Create'/'Indicator'. This will create an array indicator on the front panel, which can be renamed to 'initialized array'. Reposition the terminal of this indicator outside the sequence structure.
- Pop up on the terminal and select 'Create'/'Local Variable'. Position the local variable node inside frame 0. Next connect the output of the 'Initialize Array' node to the local variable node.
- Connect the desired constant values to the 'Initalize Array' node. Pop up on it's connectors and select 'Create'/'Constant' to create the right numerical constants.
- Add a frame after this frame.
- Use frame 1 to fill the array with random values.
- Add two nested 'For Loops' that both will count to 20.
- Add a 'Replace Array Subset' node.
- Add a 'Random number (0-1)' node.
- Add a 'Multiplication' node.
- Add two local variables for 'initialized array'. Use one to read from - pop up on one of the local variables node and select 'Change to read'- by wiring it to the 'Replace Array Subset' input. Use one to write to by wiring it to the 'Replace Array Subset' output.
- Add a frame after this frame.
- Use frame 2 to put the array data in an intensity graph.
- From the 'Controls' palette put a intensity graph on the front panel.
- In the diagram place the terminal of the intensity graph inside frame 2.
- Add a local variable for 'initialized array', enable reading from it, and connect it to the intensity graph terminal.
Downloads
array-elements.vi
The vi as described in the text.
See also...
- How to do basic array calculations.
- How to use arrays in 'for loops'.
Bart Boshuizen, 2005/02/02