arrays in labview with examples: tutorial 5

In this tutorial we will focus on learning the working of 1D array and I tried to be brief as well as precise with the description of every little concept. First, there is the introduction to arrays and then a program explaining the functionality of simple 1D integer type array. After that, there is the functionality description and a small note on the working of some of the function blocks related to arrays. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.

Introduction to arrays in labview

An object holder that can store a fixed number of values of a specific data type (discussed in previous tutorials) is known as an Array. At the time of creation on array the length is defined and its length is fixed during the run time.In the 2nd tutorial the example of writing you first program we have used a string saying “Hello World!!” which was nothing alien but an array of data type ‘String’.However, in LabView we have different definitions of an Array. A sequence of objects of same size and type stored in one variable or at one place is defined as an array. The objects or individual data in an array is called and element of an array. In a VI, one can have an array of integer, float or string as well.

In computer VIs or programs the purpose of and array is to organize data in such a way that the related set of values can easily be accessed or searched at the time of need. For example, at airports arrays can be used to store the list of. For examples a librarian can use arrays to store the titles of all the books currently present in the library.Mostly, arrays are used in data structures, a subject studied by almost every electrical or software engineer. It use in data structures is to make stacks and queues. But the concepts of stacks and queues have nothing to do with the LabView it’s just one of the applications of arrays.

labview Programming including arrays

  • Let’s now move towards the programming part. Create a program using the information provided in previous tutorials and save it by using the path file>>save as or by pressing <Ctrl+S>.
  • From, the control palette in the front panel, select Arrays, Matrix and clusters, and then select Array. The associated block on the block diagram will be of black color and it will change its color as soon as you choose the type of data to be stored in the arrays (we have seen this thing in previous tutorials on data types in labview).Array constant placement in labview

Figure 1: Placement of array.

  • The purpose of this block is to initialize the array (as we do in every programming language). We can change the number of array elements in this array constant as we have done in previous tutorial.
  • Do yourself: Change the type of the array to numeric control and set the number of elements of the array to 5.
  • After doing the above task the block diagram will look like the one shown in the figure below.Setting array type to integer

Figure 2: Integer type array control

  • Now let’s create a similar array of type integer but this time instead of using integer control using a different indicator. Right click on the array and from numeric select Vertical fill slide and drag and drop it inside the array, the one shown in the figure below.Vertical fill slide with array in labview

Figure 3: Vertical Fill slide Placement

  • This bar will act similar to an indicator and I am just using this to make you familiarize with some of the new terms in LabView and not just stuck to a few terms that we have already used.
  • Do yourself: Set the number of elements equal to 5in this indicator array too.
  • You can change the type of a control to a variable by right clicking on the block and selecting change to indicator, as shown in the figure below.Change to indicator labview

Figure 4: Changing a control to indicator.

  • Now connect both the blocks through a wire and the resulting block diagram will look like the one shown in the figure below.Array control and indicator in labview

Figure 5: Array control and indicator

  • Now come to the part where we are needed to update the value of elements of array. Just enter the values in the array panel shown in the front panel, as shown in the figure below.Filling array in labview

Figure 6: Inserting elements in an array

  • Run the program from the run button or press <Ctrl+R>. The output of the array constants will be displayed on the array indicator as shown in the figure below. The first indicator in the indicator array represents the value of first element of the array and the last element of array is indicated in the last indicator.output of array program in labview

Figure 7: Output of the code.

  • This is the basic program used to understand the working of array constant and indicator and is just a beginner’s code. Now let’s do some more working with the above program to understand the working of different blocks related to arrays.
  • From the function palette on block diagram select array and then select array size as shown in the figure below.Array size block in labview

Figure 8: Array size block

  • Connect the input terminal of this block with the output of the array constant block and at the output of this block connect an integer type indicator and give it proper label (we have learned in previous tutorials how to place and integer type indicator), using the techniques we have learned previously, and connect the indicator with the output of the size block. The resulting block diagram will look like the one shown below.array size block diagram

Figure 9: Checking the size of the array

  • Use another block namely array index block. It is placed in the function block in the array section named as index array, as shown in the figure below.Array index block in labview

Figure 10: Array index block

  • Connect the upper input of this index array block at the output of the array constant and at the lower input connect a constant of type integer and at the output of this index array block with an integer type indicator, as you have done previously for the case of array size block.Array indexing in labview

Figure 11: Array indexing

  • Change the value of the constant at the input of index array block to 3, and then run the program from the run button or by pressing <Ctrl+R>.Running the array program in labview

Figure 12: Results of updated program

The results of the program reminded me to talk about the indexes of the arrays. The index of arrays starts from zero and ends at size of array-1. As we have seen in the above example that giving the index of 3 returns the value of 4th element. Tying zero in the index constant, whereas, will return us the value of first element and so on.

Exercise for array using in labview

  • Try using the block namely reverse ID array, and understand its functionality.

Hint:  It is present in the function palette’s array section.

  • Instead of using integer array try to work with 1D Boolean and float rray to increase your understandings about arrays.

<< Previous article                                                          Next Article>>

Leave a Comment