LabVIEW is a graphical programming environment that uses visual blocks to develop programs called Virtual Instruments (VIs). It offers numerous functions for manipulating arrays, including indexing, reshaping, sorting, etc. This article extensively discusses initialising arrays in LabVIEW with suitable examples. By reading the article, you will gain sound exposure to auto-indexing, using array constants for initialisation, proper indexing for memory efficiency, optimising loops, and many more.
LabVIEW is a graphical language that allows you to program using visual blocks instead of text. It supports many data types, including arrays, Boolean, numeric, and string. You can use arrays in LabVIEW to manipulate large sets of data.
In this article, we discuss initialising arrays in detail and understand how to use various LabVIEW array functions to manipulate data efficiently.
Table of Contents:
In LabVIEW, an array consists of elements and dimensions. Elements represent the data of the Array, whereas dimensions represent the array’s size.
A LabVIEW array is a data structure that can hold elements of the same data type. In other words, an array can be a control or an indicator but not a mixture of the two.
A LabVIEW array simplifies storing large data sets and seamlessly supports ID, 2D, and 3D arrays.
LabVIEW offers many array functions to create and manipulate arrays. The functions are in the Array Palette under the Functions Palette in the LabVIEW environment.
Below are some of the LabVIEW Array functions:
Examples
Array functions automatically resize the dimensions of the input array that you wire.
Let’s look at some examples of using array functions to manipulate data.
Case 1: If you perform wiring a one-dimensional array using an array function, the function shows a single index input. If you wire a two-dimensional array to the same function, it shows two index inputs — one for the row index and one for the column index.
In the above Figure, input to the index array function is a 1D array. By providing the index value in the output, you get the array element corresponding to the index value.
Case 2: When connecting a 2D array as input, the index array function automatically resizes to receive two index inputs.
The above figure provides the index array function with a two-dimensional array as input. The row index value is provided to the index array function. At the output, you will get a one-dimensional array and a row of the two-dimensional input array.
Case 3: The index array function returns the same if you need a single array element from a 2D array input.
The above figure gives a two-dimensional array as input to the Index Array function. In this case, the array function receives both row and column index values. The output is an element based on the row and column indices provided.
If you would like to Enrich your career and become a professional in LabVIEW, then visit Mindmajix - A Global online training platform: “LabVIEW Training” Course. This course will help you to achieve excellence in this domain. |
LabVIEW allows you to initialise arrays. When you initialise an array, you define the number of elements in each dimension. In addition, you will determine the contents of the elements. Note that an uninitialised array has a dimension but no element.
You can use the initialise array function to create an n-dimensional array where each element is initialised according to the element's value. The elements can be any scalar type.
You can use the positioning tool to resize the function and increase the dimension of the output array.
The above figure shows the inputs and output of the initialise array function. Element and dimension size are the inputs, and the initialised array is the output. Here, the dimensions can be a number.
Example
Working and manipulating arrays is an important part of LabVIEW development. You will use both 1D and 2D arrays in all your applications.
In the LabVIEW platform, you can initialise an array on the front panel using the control palette:
Below is the step-by-step procedure for the same.
Auto-indexing in LabVIEW enables the automatic processing of arrays in loops. It supports iterating through every element of an array. So, you don’t need to specify indices manually.
In other words, if you wire an array to a 'For/While' Loop input tunnel, you will process every element in that array with auto-indexing.
If you auto-index an array output tunnel, the output array gets a new element from every loop iteration. The wire connecting the output tunnel to the array indicator gets bolder when it changes to an array at the loop border.
By default, LabVIEW enables auto-indexing for all the arrays you wire to ‘For’ loops. It occurs for every output tunnel that you build.
To apply auto-indexing, you can use the below procedure.
If you want to disable auto-indexing, right-click the tunnel. Another way is to go to the shortcut menu and select disable indexing.
You can also disable auto-indexing if only the last value passes to the tunnel. You can use 'For’ loops to process array elements individually.
LabVIEW defines the count terminal to the array size if you apply auto-indexing to an array wired to a 'For' Loop input terminal. Therefore, you do not need to wire the count terminal.
Example:
The number of times the for loop runs is equal to the number of array elements. The image below shows this. The run arrow is generally broken if the 'For' Loop count terminal is not wired.
If you enable auto-indexing for two tunnels, the count changes to the smaller one out of the two. The image below depicts the same.
If you wire the count terminal as shown in the figure below, the count changes to the smaller of the two.
Related Article : LabVIEW Interview Questions
LabVIEW allows inserting an element in any row or column in 1D or 2D arrays. The key parameters used to insert elements into arrays are array, index, and element.
Use-case:
You insert elements into an array when adding data points in real-time. If you want to modify array elements based on needs, you insert elements into arrays.
How to add elements in arrays?
To add an element to a 1D array, follow the below procedure.
If you want to add a row or column to a 2D array, follow the procedure below.
Alternatively, you can insert elements, columns, rows, and pages into arrays using the ‘Insert Into Array’ function.
Following is the step-by-step procedure to insert elements, rows, columns or pages in an array.
You can delete an element from a 1D array. Similarly, you can remove a subset from a two-dimensional array.
How to delete elements from arrays?
The procedure below will help you delete an element in a 1-D array.
Delete a row or column in a 2-D array using the following procedure.
You can also delete elements, columns, rows, and pages using the ‘delete from array’ function in arrays.
You can programmatically delete an element, row, column or page within an array. You can delete a row or a column from an array of 2D or more. Similarly, LabVIEW allows you to delete a page from an array of 3D or more.
Below is the step-by-step procedure to delete rows, columns, elements, or pages in an array.
LabVIEW array constant is a predefined array that has fixed data. By passing array constants in an array, you can avoid modifying its elements in runtime.
You can use array constants to store constant data. Array constants are also helpful for passing data into a sub VI.
Use-case:
You can use array constants when:
How do you create an array constant?
In LabVIEW, You can create an array constant on the block diagram by merging an array with a constant. The constant can be a numeric, Boolean, path, string, or cluster.
You can create an array constant by copying or dragging an existing array on the front panel of the block diagram. You will create a constant of the same data type.
Alternatively, you can use the following step-by-step procedure to create an array constant in the block diagram.
Related Article : Customizing Graphs And Charts In Labview
You can use array indicators to display array contents on the front panel of your VI. This lets you view the array elements and monitor your program's output.
Interestingly, you can customise the appearance of array indicators, such as resizing or formatting them. It helps interpret the data during execution.
You can build the LabVIEW front panel with controls and indicators. These are the VI's input and output terminals, respectively.
Controls can be knobs, push buttons, dials, or others. On the other side, Indicators are LEDs, graphs, and other displays.
Controls simulate input devices and supply data to the VI's block diagram. Indicators simulate output devices and display the data the block diagram acquires
The figure below shows that every control or indicator has a data type. The data types are numeric, Boolean, and string.
The numeric data type shown in Figure can be of various types, such as integer or real. The numeric control and indicator are the most commonly used numeric objects.
The Boolean data type represents data with only two parts, TRUE and FALSE or ON and OFF, as shown in Figure (b). You can use Boolean controls and indicators to enter and display Boolean values. Boolean objects simulate push buttons, switches, and LEDs.
Figure (c) shows the string data type, a sequence of ASCII characters. You can use string controls to receive text from a user, such as a password or user name, or indicators to display text to the user.
Below is a list of some of the best practices you can apply to work efficiently with arrays in LabVIEW.
Let’s see them!
Summary:
1. Why should I learn LabVIEW?
Ans: Here are the reasons why learning LabVIEW is crucial.
2. How does LabVIEW differ from PLC and SCADA?
Ans:
3. Which one is better- LabVIEW or Matlab?
Ans: You can employ LabVIEW for industry automation, control and monitoring, hardware interfacing, etc. On the other hand, you can use Matlab for data analysis, numerical computing, simulation, etc.
LabVIEW provides a visual interface to users for programming. Conversely, Matlab provides a command interface and demands coding knowledge. Hence, choosing between LabVIEW and Matlab depends on user needs and expertise in handling the tool.
4. How to become a competent LabVIEW developer?
Ans:
In short, initialising arrays in LabVIEW helps define the number of array elements and their contents. You can use array functions to manipulate arrays, including inserting, deleting, splitting, etc. Array constants and indicators are powerful tools for developing more dynamic applications.
Want to learn more about LabVIEW? Step into MindMajix's LabVIEW training. Attending this training will enhance your understanding of the LabVIEW environment and your expertise in managing large data sets and complex LabVIEW programming.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
LabVIEW Training | Dec 17 to Jan 01 | View Details |
LabVIEW Training | Dec 21 to Jan 05 | View Details |
LabVIEW Training | Dec 24 to Jan 08 | View Details |
LabVIEW Training | Dec 28 to Jan 12 | View Details |
I am Ruchitha, working as a content writer for MindMajix technologies. My writings focus on the latest technical software, tutorials, and innovations. I am also into research about AI and Neuromarketing. I am a media post-graduate from BCU – Birmingham, UK. Before, my writings focused on business articles on digital marketing and social media. You can connect with me on LinkedIn.