LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

global variable array of clusters values extract

hello

I have a global variable which is an array out of clusters. in theses
clusters I have two numerical values. I would like to save the content
of the array into a file. for this reason I have to extract the values
and to write them into a "normal" array.
but up to now I am not able to extract the data

greetings alex
0 Kudos
Message 1 of 3
(3,663 Views)
If you want to save an array just containing the two numerical values of the cluster arra wire the cluster array to a for-loop. Outside the loop check how many elements are in the cluster array and initialize a shift register with e.g. a 2D array that has 2 columns (one for each of the two values) and the same number of rows as the number of cluster elements...Now inside the for loop you unbundle the two values and use the replace array element to put the values into the 2D array...the output from the right shift register terminal will be a 2D table containing the values...ready to be saved.

Using a global to hold arrays is generally not a good idea. Globals create copies of themselves for each reference so your applicaton wil use much more memory than real
ly needed, run slower and may be prone to race conditions. Instead use a functional global.

I have attached a small example that illustrates both the unbundling of two values from within an array of clusters and the use of a functional global instead of a global. Just run the UnbundleAndFuncGlb_Demo.vi

The functional global is here made to work just like a global, however you can easily incorporate much more effective ways of handling the cluster when using a functional global. You could e.g. add a function to the global that allows you to initialize the array to a certain size, and then functions to replace and read one element at a time or a section of the array...
0 Kudos
Message 2 of 3
(3,663 Views)
You don't need to build a numeric array to extract the numerics from a cluster and write them to a file. You can extract the numerics using a For loop with Unbundle by Name in the For loop. You can write to file one numeric at a time in the same loop.
But if you want to create a second array:
Use Array Size (from the Array function palette) to get the size of your global array. Use Initialize Array (from the Array function palette) to create a numeric array big enough to hold all the numerics. If you want a 1-dimensional array and your cluster had two numerics, initialize the new array twice as big as the global array. In a loop, use Unbundle By Name (from the Cluster function palette) to extract the numerics from the cluster, then use Replace Array Subset
(from the Array function palette) to write the numerics to the array. You can resize the Replace Array Subset function (by grabbing the bottom of the function and pulling in down one step) so you can write both elements at once.
See the attached LabView 6.1 example.
0 Kudos
Message 3 of 3
(3,663 Views)