LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

manipulating certain elements in an array

Hi all,

I am having some difficulty manipulating arrays within LabVIEW.  I would like to select a certain element in several different arrays and then calculate the mean of those elements and display it to the user.  For example, if I have three different arrays, I want to select the first value in each array and determine the average between those three elements.  Does this involve using several  initialized arrays?
I'm fairly new to LabVIEW and would appreciate any help.

Thank you all!
0 Kudos
Message 1 of 10
(3,988 Views)

maybe start by browsing the array pallette with the context help on (help - show constext help).

that will give you a first idea how to play with arrays. then browse examples (help - find examples), and search for "array" - there you will find beginning examples and ideas how to imlpement waht you need.

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 2 of 10
(3,967 Views)
Well, for this you don't need to manipulate the arrays, they remain the same during the processing of this task. You just need to use index array to get the desired elements. Now you could build these elements into a new array and use mean from the statistics palette. You could also use "add array elements" and divide by the array size.
 
How complicated are your requirements? Do you always want to share the index between all input arrays or can the indices be random (for example: average the fist element of array A, 5th element of array B, ad last element of array C).
 
You definitely don't need to initialize any arrays, because it seems you already start out with arrays. Maybe I don't understand what you mean by "initialize"?
 
Are all arrays of the same lenght? Do you want to process the entire arrays calculating the mean of each slice? In this case an autoindexing FOR loop would fit the bill.
 
Why don't you attach a simple program containing your arrays and tell us what kind of output you expect. You should be able to do all that with code the size of a postage stamp. 🙂
0 Kudos
Message 3 of 10
(3,968 Views)
What I'd like to do eventually, is have the user input several different file names.  And then assign these files to several different arrays.  I won't know the actual number of files they input until the end.  I would like to calculate the mean of the first elements of each array, the mean of the second elements of each array, the mean of the third elements of each array etc...I'd like the output show up in a table.  What I've attempted to do is write code that asks the user for file input and then write this to a file.  Then I am opening the file and trying to store the values into an array (arrayOct9). I guess I have other issues in addition to the calcualting the mean of each slice in several arrays.  
0 Kudos
Message 4 of 10
(3,934 Views)

Well, we have missing VIs and very strange constructs. For example you are trying to take the mean of an array of filenames instead of the containing data. You also spin the while loop, but only retain the last filename. Maybe you want to autoindex at the loop boundary. I would recommend to do a few general LabVIEW tutorials.

Here's a quick draft how things could be done.

I have no idea how your data is organized inside the file, so you certainly need to modify the attached draft so your data is read correctly. Still, maybe it can give you some ideas.

0 Kudos
Message 5 of 10
(3,921 Views)
I'm sorry about that.  I knew my original file needed some additional work.  Am I right in thinking that if I would like to calcualte the means of the second row, I would do the same thing as the code above? 

Thanks so much for your generous help.
0 Kudos
Message 6 of 10
(3,902 Views)


@econwendy wrote:
Am I right in thinking that if I would like to calcualte the means of the second row, I would do the same thing as the code above? 

The basics would remain the same, however you would need to read the full 2D array, then slice out the second row (using index array with one index disconnected) ) before processing as shown.
Message 7 of 10
(3,879 Views)
I'm having trouble trying to extract the elements out of the second row of the array.  Does this have something to do with the read from measurement file properties?  Instead of selecting first row, should I select all rows?
0 Kudos
Message 8 of 10
(3,848 Views)
It all depends how your data is organized. In my example, you would use the "all rows" output of "read from spreadsheet file", giving you a 2D array. Now you can slice out the desired row using "index array" as described earlier.
 
Do you have an example datafile? "read from measurement file" will probably work too if you configure it right.
0 Kudos
Message 9 of 10
(3,827 Views)
Thanks for all your help.  I think I've got it figured out now. 
0 Kudos
Message 10 of 10
(3,806 Views)