05-16-2016 05:04 AM
Stanford University currently use an algorithm within its Coursera NLP Course which enables you to find out the same two arrays in LabVIEW. In our latest LabVIEW tip we will show you how to do this.
For example, imagine you have two arrays of [1, 2, 3, 4, 5, 6] and [2, 4, 6, 8, 10]. You notice that the same two elements of [2, 4, 6] feature within each array.
This is possible as LabVIEW has a ‘Search in LabVIEW 1D array function’ which can work out if an element is an array.
This hidden function within LabVIEW iterates itself through an array in LabVIEW until it either finds the same elements or completes the process if nothing is found. The iteration can take up to N times where N is the length of the array. When you wish to compare two arrays with the lengths N and M respectively, the iteration could take up to N*M times.
As a test example, we prepared two arrays in LabVIEW with the lengths of 100k and 90k, using the LabVIEW ‘Search 1D Array’ function to find out if the same elements exist, as demonstrated in the figure below.
Test0 – The code iteratively checks if the element of 90k array can be found in the 100k array, and remove the element in the 100k array if found. The running time for the above code was 7.3 seconds as the array size can be large, it could take up to 100,000 * 90,000 = 9,000,000 iterations to calculate this.
There is an alternative way of doing this which is outlined in the course itself, where the algorithm moves both arrays simultaneously and therefore reduces the running time, as demonstrated in the figure below.
Algorithms – The two arrays in LabVIEW compare the first elements from the beginning and both move forwards if the two elements are equivalent. If the values do not match, move the array with the smaller value and carry on comparing with the next value. This calculation takes up to N + M (the sum of the two lengths) iterations. When the array is large, it saves a lot of time.
The following is the pseudo code of the ‘merge’ algorithm, as demonstrated in the figure below.
Here is how it look within the LabVIEW implementation.
And the test VI:
The code itself takes 0.03 second to compute, which is more than 200 times faster than if using the ‘Sort 1D array’ function beforehand. The code itself will also work well with text arrays in LabVIEW.
LabVIEW Architect
Bo was exposed to LabVIEW when he started his Ph.D. in 2007. He has been developing biological devices for the neuroscience lab since then, and has developed a high-speed compressive-sampling camera and a real-time spatial light modulator (SLM) for his Ph.D. A precise flow control device for neuron feeding, a Daphnia heart beat monitoring device and a multiple-electrode array (MEA) for monitoring neural activity were developed when he worked as a Post Doc.
Bo is now working on solving signal processing problems and applying Machine Learning to reduce manual operation. Bo regularly contributes to the Austin Consultants blog, maintains his own personal blog at bofu.me and is a Certified LabVIEW Architect.
The post LabVIEW Tip: Finding two arrays in LabVIEW appeared first on Austin Consultants.