LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pull data values from 1-D array

Solved!
Go to solution

Hi, I had trouble finding information on the Discussion forums on this topic.

 

I have a 1-D array (1x1024 values) and would like to pull certain values out it. For example, I might like to pull values 435 through 567, then do some mathematical operations on those values. There would be two numeric controls on the front panel to set these two numbers. How would I go about doing this?

 

Thank you!

0 Kudos
Message 1 of 7
(3,862 Views)

In Range and coerce is useful here.

 

Also, conditional tunnel on a loop with auto-indexing.

0 Kudos
Message 2 of 7
(3,860 Views)

urlmichael wrote:

I have a 1-D array (1x1024 values) and would like to pull certain values out it.


That (1x1024) is a 2D array where one dimension is size=1. Do you actually have a 1D array with 1024 values instead?


@urlmichael wrote:

For example, I might like to pull values 435 through 567, then do some mathematical operations on those values. 


The term "pull" is rarely used in LabVIEW and it is not entirely clear what it means here. Is it sufficient to iterate over the original data and do some operation on the special values right there or do you want to first create a new array that only contains the special values? Should they be removed from the original array or also stay there? Should they be replaced with a special values (e.g. zero) in the original array? What should happen to the other array elements that don't match?

 

Can you be a bit more specific about the "mathematical operations"? The most appropriate solution will depend on it.

0 Kudos
Message 3 of 7
(3,841 Views)

Do you mean Indexes 435 through 567? To get the data at those indexes use Array Subset. Wire the smaller index to the Index terminal and the difference between the indexes to the Length terminal.

 

Lynn

Message 4 of 7
(3,838 Views)

I was mistaken - it is a 2-D array with only one row.

 

The 1024 wide array is being generated from an instrument. It is putting out 8-bit integers. I would like to take the data values from certain range and take the average of them, then store that average in a new array. I do not particularly care what happens to the array after I get the data values from it, since the average across the specified range is really what I'm looking for.

 

Ex:

 

 

2342       4344       4444     8576     9485     5554     3423     2342     2342

 

Input range 2 through 5. That would get the numbers  4344, 4444, 8576, and 9485. Then I would add them together, divide by the number that there are (5-2+1=4) and get an average of 6712.25. I would then input 6712.25 into an array for storage and saving. The end result is an array with the average over a certain range for many different original 1024 arrays (which are generated by the instrument)

0 Kudos
Message 5 of 7
(3,823 Views)

 


@urlmichael wrote:

 

2342       4344       4444     8576     9485     5554     3423     2342     2342


None of these values fit in an 8 bit integer. In order to average, you need to convert them to DBL. As already mentioned, you can use array subset also on a 2D array, convert to a 1D array using "index array" (or vice versa, use index array to convert to a 1D array followed by array subset), then followed by "mean.VI".

 

You can also extract the 2D array subset followed by "add array elements", then divide by the product of the dimensions (array size followe by "multiply array elements"). 

 

(There are also ways that don't require extracting any sub-arrays of course)


@urlmichael wrote:

I would like to take the data values from certain range and take the average of them, then store that average in a new array.


An average is a simple scalar, why should the output be an array? Do you want an array with a single element?

0 Kudos
Message 6 of 7
(3,816 Views)
Solution
Accepted by topic author urlmichael

Also, in LabVIEW array indexes start at zero, so the 2 through 5 in your example represents indexes 1 through 4. The code shown below will do that.

 

Extract from array.png

If you need to process mulitple sets of data (which is what I interpret as the reason for putting the result into an array) put the code above inside a loop.

 

Lynn

Message 7 of 7
(3,803 Views)